]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix truncation warnings in posix/tst-glob_symlinks.c.
authorJoseph Myers <joseph@codesourcery.com>
Mon, 18 Dec 2017 22:54:01 +0000 (22:54 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Mon, 18 Dec 2017 22:54:01 +0000 (22:54 +0000)
The test posix/tst-glob_symlinks.c fails to build with GCC mainline:

tst-glob_symlinks.c: In function 'do_test':
tst-glob_symlinks.c:124:30: error: 'snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
   snprintf (buf, sizeof buf, "%s?", dangling_link);
                              ^~~~~
tst-glob_symlinks.c:124:3: note: 'snprintf' output between 2 and 4097 bytes into a destination of size 4096
   snprintf (buf, sizeof buf, "%s?", dangling_link);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tst-glob_symlinks.c:128:30: error: 'snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
   snprintf (buf, sizeof buf, "%s*", dangling_link);
                              ^~~~~
tst-glob_symlinks.c:128:3: note: 'snprintf' output between 2 and 4097 bytes into a destination of size 4096
   snprintf (buf, sizeof buf, "%s*", dangling_link);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This patch fixes the test to avoid such truncation warnings by
increasing the buffer in question by one byte, to ensure it can hold
any possible result of %s? or %s* formats where %s comes from a buffer
of size PATH_MAX.

Tested compilation with build-many-glibcs.py for aarch64-linux-gnu.

* posix/tst-glob_symlinks.c (do_test): Increase size of buf.

ChangeLog
posix/tst-glob_symlinks.c

index f90ddb5bd8bbe1d37b1fd4c930c3cf490ec72ceb..a444183198bc0c38826a6e834d3a1e1930205281 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2017-12-18  Joseph Myers  <joseph@codesourcery.com>
 
+       * posix/tst-glob_symlinks.c (do_test): Increase size of buf.
+
        * string/tester.c (test_strncat): Also disable -Warray-bounds
        warnings for two tests.
 
index 5c4b4ecf4a4035136698dbe7d4d5a59f299a2537..3a86f4c8cc90e226f46bdc891372d34415aed1ed 100644 (file)
@@ -94,7 +94,7 @@ do_prepare (int argc, char *argv[])
 static int
 do_test (void)
 {
-  char buf[PATH_MAX];
+  char buf[PATH_MAX + 1];
   glob_t gl;
 
   TEST_VERIFY_EXIT (glob (valid_link, 0, NULL, &gl) == 0);