mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-08 14:20:07 +00:00
Add tests for fortification of bcopy and bzero.
* debug/tst-chk1.c: Add tests for fortification of bcopy and bzero.
This commit is contained in:
parent
6f9d4f595e
commit
d3bf0bade6
@ -1,3 +1,7 @@
|
|||||||
|
2016-08-19 Zack Weinberg <zackw@panix.com>
|
||||||
|
|
||||||
|
* debug/tst-chk1.c: Add tests for fortification of bcopy and bzero.
|
||||||
|
|
||||||
2016-08-18 Torvald Riegel <triegel@redhat.com>
|
2016-08-18 Torvald Riegel <triegel@redhat.com>
|
||||||
|
|
||||||
[BZ #20477]
|
[BZ #20477]
|
||||||
|
@ -143,6 +143,11 @@ do_test (void)
|
|||||||
if (memcmp (buf, "aabcdefghi", 10))
|
if (memcmp (buf, "aabcdefghi", 10))
|
||||||
FAIL ();
|
FAIL ();
|
||||||
|
|
||||||
|
memcpy (buf, "abcdefghij", 10);
|
||||||
|
bcopy (buf, buf + 1, 9);
|
||||||
|
if (memcmp (buf, "aabcdefghi", 10))
|
||||||
|
FAIL ();
|
||||||
|
|
||||||
if (mempcpy (buf + 5, "abcde", 5) != buf + 10
|
if (mempcpy (buf + 5, "abcde", 5) != buf + 10
|
||||||
|| memcmp (buf, "aabcdabcde", 10))
|
|| memcmp (buf, "aabcdabcde", 10))
|
||||||
FAIL ();
|
FAIL ();
|
||||||
@ -151,6 +156,10 @@ do_test (void)
|
|||||||
if (memcmp (buf, "aabcdabcjj", 10))
|
if (memcmp (buf, "aabcdabcjj", 10))
|
||||||
FAIL ();
|
FAIL ();
|
||||||
|
|
||||||
|
bzero (buf + 8, 2);
|
||||||
|
if (memcmp (buf, "aabcdabc\0\0", 10))
|
||||||
|
FAIL ();
|
||||||
|
|
||||||
strcpy (buf + 4, "EDCBA");
|
strcpy (buf + 4, "EDCBA");
|
||||||
if (memcmp (buf, "aabcEDCBA", 10))
|
if (memcmp (buf, "aabcEDCBA", 10))
|
||||||
FAIL ();
|
FAIL ();
|
||||||
@ -175,6 +184,11 @@ do_test (void)
|
|||||||
if (memcmp (buf, "aabcdefghi", 10))
|
if (memcmp (buf, "aabcdefghi", 10))
|
||||||
FAIL ();
|
FAIL ();
|
||||||
|
|
||||||
|
memcpy (buf, "abcdefghij", l0 + 10);
|
||||||
|
bcopy (buf, buf + 1, l0 + 9);
|
||||||
|
if (memcmp (buf, "aabcdefghi", 10))
|
||||||
|
FAIL ();
|
||||||
|
|
||||||
if (mempcpy (buf + 5, "abcde", l0 + 5) != buf + 10
|
if (mempcpy (buf + 5, "abcde", l0 + 5) != buf + 10
|
||||||
|| memcmp (buf, "aabcdabcde", 10))
|
|| memcmp (buf, "aabcdabcde", 10))
|
||||||
FAIL ();
|
FAIL ();
|
||||||
@ -183,6 +197,10 @@ do_test (void)
|
|||||||
if (memcmp (buf, "aabcdabcjj", 10))
|
if (memcmp (buf, "aabcdabcjj", 10))
|
||||||
FAIL ();
|
FAIL ();
|
||||||
|
|
||||||
|
bzero (buf + 8, l0 + 2);
|
||||||
|
if (memcmp (buf, "aabcdabc\0\0", 10))
|
||||||
|
FAIL ();
|
||||||
|
|
||||||
strcpy (buf + 4, str1 + 5);
|
strcpy (buf + 4, str1 + 5);
|
||||||
if (memcmp (buf, "aabcEDCBA", 10))
|
if (memcmp (buf, "aabcEDCBA", 10))
|
||||||
FAIL ();
|
FAIL ();
|
||||||
@ -214,11 +232,18 @@ do_test (void)
|
|||||||
if (memcmp (buf, "aabcEcdZY", 10))
|
if (memcmp (buf, "aabcEcdZY", 10))
|
||||||
FAIL ();
|
FAIL ();
|
||||||
|
|
||||||
|
/* The following tests are supposed to succeed at all fortify
|
||||||
|
levels, even though they overflow a.buf1 into a.buf2. */
|
||||||
memcpy (a.buf1, "abcdefghij", l0 + 10);
|
memcpy (a.buf1, "abcdefghij", l0 + 10);
|
||||||
memmove (a.buf1 + 1, a.buf1, l0 + 9);
|
memmove (a.buf1 + 1, a.buf1, l0 + 9);
|
||||||
if (memcmp (a.buf1, "aabcdefghi", 10))
|
if (memcmp (a.buf1, "aabcdefghi", 10))
|
||||||
FAIL ();
|
FAIL ();
|
||||||
|
|
||||||
|
memcpy (a.buf1, "abcdefghij", l0 + 10);
|
||||||
|
bcopy (a.buf1, a.buf1 + 1, l0 + 9);
|
||||||
|
if (memcmp (a.buf1, "aabcdefghi", 10))
|
||||||
|
FAIL ();
|
||||||
|
|
||||||
if (mempcpy (a.buf1 + 5, "abcde", l0 + 5) != a.buf1 + 10
|
if (mempcpy (a.buf1 + 5, "abcde", l0 + 5) != a.buf1 + 10
|
||||||
|| memcmp (a.buf1, "aabcdabcde", 10))
|
|| memcmp (a.buf1, "aabcdabcde", 10))
|
||||||
FAIL ();
|
FAIL ();
|
||||||
@ -227,6 +252,10 @@ do_test (void)
|
|||||||
if (memcmp (a.buf1, "aabcdabcjj", 10))
|
if (memcmp (a.buf1, "aabcdabcjj", 10))
|
||||||
FAIL ();
|
FAIL ();
|
||||||
|
|
||||||
|
bzero (a.buf1 + 8, l0 + 2);
|
||||||
|
if (memcmp (a.buf1, "aabcdabc\0\0", 10))
|
||||||
|
FAIL ();
|
||||||
|
|
||||||
#if __USE_FORTIFY_LEVEL < 2
|
#if __USE_FORTIFY_LEVEL < 2
|
||||||
/* The following tests are supposed to crash with -D_FORTIFY_SOURCE=2
|
/* The following tests are supposed to crash with -D_FORTIFY_SOURCE=2
|
||||||
and sufficient GCC support, as the string operations overflow
|
and sufficient GCC support, as the string operations overflow
|
||||||
@ -284,6 +313,14 @@ do_test (void)
|
|||||||
memmove (buf + 2, buf + 1, l0 + 9);
|
memmove (buf + 2, buf + 1, l0 + 9);
|
||||||
CHK_FAIL_END
|
CHK_FAIL_END
|
||||||
|
|
||||||
|
CHK_FAIL_START
|
||||||
|
bcopy (buf + 1, buf + 2, 9);
|
||||||
|
CHK_FAIL_END
|
||||||
|
|
||||||
|
CHK_FAIL_START
|
||||||
|
bcopy (buf + 1, buf + 2, l0 + 9);
|
||||||
|
CHK_FAIL_END
|
||||||
|
|
||||||
CHK_FAIL_START
|
CHK_FAIL_START
|
||||||
p = (char *) mempcpy (buf + 6, "abcde", 5);
|
p = (char *) mempcpy (buf + 6, "abcde", 5);
|
||||||
CHK_FAIL_END
|
CHK_FAIL_END
|
||||||
@ -300,6 +337,14 @@ do_test (void)
|
|||||||
memset (buf + 9, 'j', l0 + 2);
|
memset (buf + 9, 'j', l0 + 2);
|
||||||
CHK_FAIL_END
|
CHK_FAIL_END
|
||||||
|
|
||||||
|
CHK_FAIL_START
|
||||||
|
bzero (buf + 9, 2);
|
||||||
|
CHK_FAIL_END
|
||||||
|
|
||||||
|
CHK_FAIL_START
|
||||||
|
bzero (buf + 9, l0 + 2);
|
||||||
|
CHK_FAIL_END
|
||||||
|
|
||||||
CHK_FAIL_START
|
CHK_FAIL_START
|
||||||
strcpy (buf + 5, str1 + 5);
|
strcpy (buf + 5, str1 + 5);
|
||||||
CHK_FAIL_END
|
CHK_FAIL_END
|
||||||
@ -377,6 +422,14 @@ do_test (void)
|
|||||||
memmove (a.buf1 + 2, a.buf1 + 1, l0 + 9);
|
memmove (a.buf1 + 2, a.buf1 + 1, l0 + 9);
|
||||||
CHK_FAIL_END
|
CHK_FAIL_END
|
||||||
|
|
||||||
|
CHK_FAIL_START
|
||||||
|
bcopy (a.buf1 + 1, a.buf1 + 2, 9);
|
||||||
|
CHK_FAIL_END
|
||||||
|
|
||||||
|
CHK_FAIL_START
|
||||||
|
bcopy (a.buf1 + 1, a.buf1 + 2, l0 + 9);
|
||||||
|
CHK_FAIL_END
|
||||||
|
|
||||||
CHK_FAIL_START
|
CHK_FAIL_START
|
||||||
p = (char *) mempcpy (a.buf1 + 6, "abcde", 5);
|
p = (char *) mempcpy (a.buf1 + 6, "abcde", 5);
|
||||||
CHK_FAIL_END
|
CHK_FAIL_END
|
||||||
@ -393,6 +446,14 @@ do_test (void)
|
|||||||
memset (a.buf1 + 9, 'j', l0 + 2);
|
memset (a.buf1 + 9, 'j', l0 + 2);
|
||||||
CHK_FAIL_END
|
CHK_FAIL_END
|
||||||
|
|
||||||
|
CHK_FAIL_START
|
||||||
|
bzero (a.buf1 + 9, 2);
|
||||||
|
CHK_FAIL_END
|
||||||
|
|
||||||
|
CHK_FAIL_START
|
||||||
|
bzero (a.buf1 + 9, l0 + 2);
|
||||||
|
CHK_FAIL_END
|
||||||
|
|
||||||
# if __USE_FORTIFY_LEVEL >= 2
|
# if __USE_FORTIFY_LEVEL >= 2
|
||||||
# define O 0
|
# define O 0
|
||||||
# else
|
# else
|
||||||
|
Loading…
Reference in New Issue
Block a user