]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Don't overrun `tmpdir` buffer with sprintf
authorNgie Cooper <yanegomi@gmail.com>
Sun, 11 Dec 2016 00:22:10 +0000 (16:22 -0800)
committerNgie Cooper <yanegomi@gmail.com>
Sun, 11 Dec 2016 00:22:10 +0000 (16:22 -0800)
If progname is sufficiently large enough, it would overflow the `tmpdir`
buffer, causing an illegal memory access

Reported by: Coverity
CID: 1331594

tar/test/main.c

index 6077af5f0217c8c3d1d51845dbd8896e557ac2bf..6bc35578337247a69e72cd05219d12673c3cf615 100644 (file)
@@ -2958,8 +2958,8 @@ 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);
+               snprintf(tmpdir, sizeof(tmpdir), "%s/%s.%s-%03d", tmp,
+                   progname, tmpdir_timestamp, i);
                if (assertMakeDir(tmpdir,0755))
                        break;
                if (i >= 999) {