]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Use PATH_MAX if available for temporary path buffer
authorMartin Matuska <martin@matuska.org>
Thu, 20 Sep 2018 14:52:34 +0000 (16:52 +0200)
committerMartin Matuska <martin@matuska.org>
Thu, 20 Sep 2018 15:08:36 +0000 (17:08 +0200)
Check if temporary file path fits into buffer

Fixes #1067

test_utils/test_main.c

index 2ff942c84a44d92d3dda6a7b3665710d4d2aa223..bb71217b232c0bf8064076e2eb5814d0df6c5d1e 100644 (file)
@@ -3260,7 +3260,11 @@ test_summarize(int failed, int skips_num)
 static int
 test_run(int i, const char *tmpdir)
 {
+#ifdef PATH_MAX
+       char workdir[PATH_MAX];
+#else
        char workdir[1024];
+#endif
        char logfilename[64];
        int failures_before = failures;
        int skips_before = skips;
@@ -3509,8 +3513,13 @@ main(int argc, char **argv)
        const char *progname;
        char **saved_argv;
        const char *tmp, *option_arg, *p;
-       char tmpdir[256], *pwd, *testprogdir, *tmp2 = NULL, *vlevel = NULL;
-       char tmpdir_timestamp[256];
+#ifdef PATH_MAX
+       char tmpdir[PATH_MAX];
+#else
+       char tmpdir[256];
+#endif
+       char *pwd, *testprogdir, *tmp2 = NULL, *vlevel = NULL;
+       char tmpdir_timestamp[32];
 
        (void)argc; /* UNUSED */
 
@@ -3734,8 +3743,15 @@ main(int argc, char **argv)
                strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp),
                    "%Y-%m-%dT%H.%M.%S",
                    localtime(&now));
-               sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
-                   tmpdir_timestamp, i);
+               if ((strlen(tmp) + 1 + strlen(progname) + 1 +
+                   strlen(tmpdir_timestamp) + 1 + 3) >
+                   (sizeof(tmpdir) / sizeof(char))) {
+                       fprintf(stderr,
+                           "ERROR: Temp directory pathname too long\n");
+                       exit(1);
+               }
+               snprintf(tmpdir, sizeof(tmpdir), "%s/%s.%s-%03d", tmp,
+                   progname, tmpdir_timestamp, i);
                if (assertMakeDir(tmpdir,0755))
                        break;
                if (i >= 999) {