mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
Fix string/tester.c for GCC 7 -Wstringop-overflow=.
GCC 7 has a -Wstringop-overflow= warning that includes warning for strncat with a size specified that is larger than the size of the buffer (which is dubious usage, but valid at runtime if in fact there isn't an overflow with the particular buffer contents present). string/tester.c tests such cases; this patch arranges for this warning to be ignored around relevant strncat calls. Tested compilation for aarch64 (GCC mainline) with build-many-glibcs.py; did execution testing for x86_64 (GCC 5). * string/tester.c (test_strncat): Disable -Wstringop-overflow= around tests of strncat with large sizes.
This commit is contained in:
@ -1,5 +1,8 @@
|
|||||||
2017-01-04 Joseph Myers <joseph@codesourcery.com>
|
2017-01-04 Joseph Myers <joseph@codesourcery.com>
|
||||||
|
|
||||||
|
* string/tester.c (test_strncat): Disable -Wstringop-overflow=
|
||||||
|
around tests of strncat with large sizes.
|
||||||
|
|
||||||
* malloc/tst-malloc.c: Include <libc-internal.h>.
|
* malloc/tst-malloc.c: Include <libc-internal.h>.
|
||||||
(do_test): Disable -Walloc-size-larger-than= around tests of
|
(do_test): Disable -Walloc-size-larger-than= around tests of
|
||||||
malloc with negative sizes.
|
malloc with negative sizes.
|
||||||
|
@ -353,28 +353,70 @@ test_strncat (void)
|
|||||||
mechanism. */
|
mechanism. */
|
||||||
it = "strncat";
|
it = "strncat";
|
||||||
(void) strcpy (one, "ijk");
|
(void) strcpy (one, "ijk");
|
||||||
|
DIAG_PUSH_NEEDS_COMMENT;
|
||||||
|
#if __GNUC_PREREQ (7, 0)
|
||||||
|
/* GCC 7 warns about the size passed to strncat being larger than
|
||||||
|
the size of the buffer; this is deliberately tested here.. */
|
||||||
|
DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow=");
|
||||||
|
#endif
|
||||||
check (strncat (one, "lmn", 99) == one, 1); /* Returned value. */
|
check (strncat (one, "lmn", 99) == one, 1); /* Returned value. */
|
||||||
|
DIAG_POP_NEEDS_COMMENT;
|
||||||
equal (one, "ijklmn", 2); /* Basic test. */
|
equal (one, "ijklmn", 2); /* Basic test. */
|
||||||
|
|
||||||
(void) strcpy (one, "x");
|
(void) strcpy (one, "x");
|
||||||
|
DIAG_PUSH_NEEDS_COMMENT;
|
||||||
|
#if __GNUC_PREREQ (7, 0)
|
||||||
|
/* GCC 7 warns about the size passed to strncat being larger than
|
||||||
|
the size of the buffer; this is deliberately tested here.. */
|
||||||
|
DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow=");
|
||||||
|
#endif
|
||||||
(void) strncat (one, "yz", 99);
|
(void) strncat (one, "yz", 99);
|
||||||
|
DIAG_POP_NEEDS_COMMENT;
|
||||||
equal (one, "xyz", 3); /* Writeover. */
|
equal (one, "xyz", 3); /* Writeover. */
|
||||||
equal (one+4, "mn", 4); /* Wrote too much? */
|
equal (one+4, "mn", 4); /* Wrote too much? */
|
||||||
|
|
||||||
(void) strcpy (one, "gh");
|
(void) strcpy (one, "gh");
|
||||||
(void) strcpy (two, "ef");
|
(void) strcpy (two, "ef");
|
||||||
|
DIAG_PUSH_NEEDS_COMMENT;
|
||||||
|
#if __GNUC_PREREQ (7, 0)
|
||||||
|
/* GCC 7 warns about the size passed to strncat being larger than
|
||||||
|
the size of the buffer; this is deliberately tested here.. */
|
||||||
|
DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow=");
|
||||||
|
#endif
|
||||||
(void) strncat (one, two, 99);
|
(void) strncat (one, two, 99);
|
||||||
|
DIAG_POP_NEEDS_COMMENT;
|
||||||
equal (one, "ghef", 5); /* Basic test encore. */
|
equal (one, "ghef", 5); /* Basic test encore. */
|
||||||
equal (two, "ef", 6); /* Stomped on source? */
|
equal (two, "ef", 6); /* Stomped on source? */
|
||||||
|
|
||||||
(void) strcpy (one, "");
|
(void) strcpy (one, "");
|
||||||
|
DIAG_PUSH_NEEDS_COMMENT;
|
||||||
|
#if __GNUC_PREREQ (7, 0)
|
||||||
|
/* GCC 7 warns about the size passed to strncat being larger than
|
||||||
|
the size of the buffer; this is deliberately tested here.. */
|
||||||
|
DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow=");
|
||||||
|
#endif
|
||||||
(void) strncat (one, "", 99);
|
(void) strncat (one, "", 99);
|
||||||
|
DIAG_POP_NEEDS_COMMENT;
|
||||||
equal (one, "", 7); /* Boundary conditions. */
|
equal (one, "", 7); /* Boundary conditions. */
|
||||||
(void) strcpy (one, "ab");
|
(void) strcpy (one, "ab");
|
||||||
|
DIAG_PUSH_NEEDS_COMMENT;
|
||||||
|
#if __GNUC_PREREQ (7, 0)
|
||||||
|
/* GCC 7 warns about the size passed to strncat being larger than
|
||||||
|
the size of the buffer; this is deliberately tested here.. */
|
||||||
|
DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow=");
|
||||||
|
#endif
|
||||||
(void) strncat (one, "", 99);
|
(void) strncat (one, "", 99);
|
||||||
|
DIAG_POP_NEEDS_COMMENT;
|
||||||
equal (one, "ab", 8);
|
equal (one, "ab", 8);
|
||||||
(void) strcpy (one, "");
|
(void) strcpy (one, "");
|
||||||
|
DIAG_PUSH_NEEDS_COMMENT;
|
||||||
|
#if __GNUC_PREREQ (7, 0)
|
||||||
|
/* GCC 7 warns about the size passed to strncat being larger than
|
||||||
|
the size of the buffer; this is deliberately tested here.. */
|
||||||
|
DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow=");
|
||||||
|
#endif
|
||||||
(void) strncat (one, "cd", 99);
|
(void) strncat (one, "cd", 99);
|
||||||
|
DIAG_POP_NEEDS_COMMENT;
|
||||||
equal (one, "cd", 9);
|
equal (one, "cd", 9);
|
||||||
|
|
||||||
(void) strcpy (one, "ab");
|
(void) strcpy (one, "ab");
|
||||||
@ -387,7 +429,14 @@ test_strncat (void)
|
|||||||
(void) strncat (one, "gh", 2);
|
(void) strncat (one, "gh", 2);
|
||||||
equal (one, "abcdgh", 12); /* Count and length equal. */
|
equal (one, "abcdgh", 12); /* Count and length equal. */
|
||||||
|
|
||||||
|
DIAG_PUSH_NEEDS_COMMENT;
|
||||||
|
#if __GNUC_PREREQ (7, 0)
|
||||||
|
/* GCC 7 warns about the size passed to strncat being larger than
|
||||||
|
the size of the buffer; this is deliberately tested here.. */
|
||||||
|
DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow=");
|
||||||
|
#endif
|
||||||
(void) strncat (one, "ij", (size_t)-1); /* set sign bit in count */
|
(void) strncat (one, "ij", (size_t)-1); /* set sign bit in count */
|
||||||
|
DIAG_POP_NEEDS_COMMENT;
|
||||||
equal (one, "abcdghij", 13);
|
equal (one, "abcdghij", 13);
|
||||||
|
|
||||||
int ntest = 14;
|
int ntest = 14;
|
||||||
@ -406,8 +455,16 @@ test_strncat (void)
|
|||||||
buf1[n2 + n3] = '\0';
|
buf1[n2 + n3] = '\0';
|
||||||
strcpy (buf2 + n1, "123");
|
strcpy (buf2 + n1, "123");
|
||||||
|
|
||||||
|
DIAG_PUSH_NEEDS_COMMENT;
|
||||||
|
#if __GNUC_PREREQ (7, 0)
|
||||||
|
/* GCC 7 warns about the size passed to strncat being
|
||||||
|
larger than the size of the buffer; this is
|
||||||
|
deliberately tested here.. */
|
||||||
|
DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow=");
|
||||||
|
#endif
|
||||||
check (strncat (buf1 + n2, buf2 + n1, ~((size_t) 0) - n4)
|
check (strncat (buf1 + n2, buf2 + n1, ~((size_t) 0) - n4)
|
||||||
== buf1 + n2, ntest);
|
== buf1 + n2, ntest);
|
||||||
|
DIAG_POP_NEEDS_COMMENT;
|
||||||
if (errors == olderrors)
|
if (errors == olderrors)
|
||||||
for (size_t i = 0; i < sizeof (buf1); ++i)
|
for (size_t i = 0; i < sizeof (buf1); ++i)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user