From: Jason Ish Date: Wed, 31 Oct 2018 22:41:07 +0000 (-0600) Subject: filestore: fix compiler truncation warnings X-Git-Tag: suricata-4.1.0~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=961931e73a223c6fa1fa03fd83b245efc90f9ccb;p=thirdparty%2Fsuricata.git filestore: fix compiler truncation warnings And error out if the constructed filename is truncated. --- diff --git a/src/output-filestore.c b/src/output-filestore.c index 2ce3d9dd65..2c5c908d95 100644 --- a/src/output-filestore.c +++ b/src/output-filestore.c @@ -354,7 +354,13 @@ static bool InitFilestoreDirectory(const char *dir) for (int i = 0; i <= dir_count; i++) { char leaf[PATH_MAX]; - snprintf(leaf, sizeof(leaf) - 1, "%s/%02x", dir, i); + int n = snprintf(leaf, sizeof(leaf), "%s/%02x", dir, i); + if (n < 0 || n >= PATH_MAX) { + SCLogError(SC_ERR_CREATE_DIRECTORY, + "Filestore (v2) failed to create leaf directory: " + "path too long"); + return false; + } if (!SCPathExists(leaf)) { SCLogInfo("Filestore (v2) creating directory %s", leaf); if (SCDefaultMkDir(leaf) != 0) { @@ -368,7 +374,12 @@ static bool InitFilestoreDirectory(const char *dir) /* Make sure the tmp directory exists. */ char tmpdir[PATH_MAX]; - snprintf(tmpdir, sizeof(tmpdir) - 1, "%s/tmp", dir); + int n = snprintf(tmpdir, sizeof(tmpdir), "%s/tmp", dir); + if (n < 0 || n >= PATH_MAX) { + SCLogError(SC_ERR_CREATE_DIRECTORY, + "Filestore (v2) failed to create tmp directory: path too long"); + return false; + } if (!SCPathExists(tmpdir)) { SCLogInfo("Filestore (v2) creating directory %s", tmpdir); if (SCDefaultMkDir(tmpdir) != 0) {