]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
filestore: fix compiler truncation warnings
authorJason Ish <ish@unx.ca>
Wed, 31 Oct 2018 22:41:07 +0000 (16:41 -0600)
committerVictor Julien <victor@inliniac.net>
Fri, 2 Nov 2018 14:15:28 +0000 (15:15 +0100)
And error out if the constructed filename is truncated.

src/output-filestore.c

index 2ce3d9dd65061891f46696ceabf88d9fd58ccb0f..2c5c908d954da23e7821dc147581e4f3b65e7c09 100644 (file)
@@ -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) {