output/lua: work around format truncation warnings

Use PathMerge to improve path handling and address these warnings:

output-lua.c: In function 'OutputLuaLogInitSub':
output-lua.c:657:48: warning: '%s' directive output may be truncated writing likely 1 or more bytes into a region of size between 0 and 4096 [-Wformat-truncation=]
  657 |     int ret = snprintf(path, sizeof(path),"%s%s%s", dir, strlen(dir) ? "/" : "", conf->val);
      |                                                ^~
output-lua.c:657:43: note: assuming directive output of 1 byte
  657 |     int ret = snprintf(path, sizeof(path),"%s%s%s", dir, strlen(dir) ? "/" : "", conf->val);
      |                                           ^~~~~~~~
output-lua.c:657:15: note: 'snprintf' output 1 or more bytes (assuming 4098) into a destination of size 4096
  657 |     int ret = snprintf(path, sizeof(path),"%s%s%s", dir, strlen(dir) ? "/" : "", conf->val);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ticket: #7905.
pull/13926/head
Victor Julien 2 months ago committed by Victor Julien
parent 99a79b595f
commit 7bab39d447

@ -33,6 +33,7 @@
#include "app-layer-ssh.h"
#include "app-layer-parser.h"
#include "util-time.h"
#include "util-path.h"
#include "util-lua.h"
#include "util-lua-common.h"
#include "util-lua-http.h"
@ -654,10 +655,13 @@ static OutputInitResult OutputLuaLogInitSub(SCConfNode *conf, OutputCtx *parent_
const char *dir = mc->script_dir;
char path[PATH_MAX] = "";
int ret = snprintf(path, sizeof(path),"%s%s%s", dir, strlen(dir) ? "/" : "", conf->val);
if (ret < 0 || ret == sizeof(path)) {
SCLogError("failed to construct lua script path");
goto error;
if (strlen(dir) > 0) {
if (PathMerge(path, sizeof(path), dir, conf->val) < 0) {
SCLogError("failed to construct lua script path");
goto error;
}
} else {
strlcpy(path, conf->val, sizeof(path));
}
SCLogDebug("script full path %s", path);

Loading…
Cancel
Save