diff options
author | Jakub Jelinek <jakub@redhat.com> | 2005-08-24 07:23:32 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2005-08-24 07:23:32 +0000 |
commit | 8bf34d8a27ffed48c7a43b7c7347235d389b0946 (patch) | |
tree | 36a2efd2a73c3d642829770b47f753e0160dd411 /debug | |
parent | d2b0f6344275bc3624e47a4d02b67a7e131f6f56 (diff) | |
download | glibc-8bf34d8a27ffed48c7a43b7c7347235d389b0946.tar.gz glibc-8bf34d8a27ffed48c7a43b7c7347235d389b0946.tar.xz glibc-8bf34d8a27ffed48c7a43b7c7347235d389b0946.zip |
Updated to fedora-glibc-20050824T0705
Diffstat (limited to 'debug')
-rw-r--r-- | debug/mbsnrtowcs_chk.c | 2 | ||||
-rw-r--r-- | debug/mbsrtowcs_chk.c | 2 | ||||
-rw-r--r-- | debug/mbstowcs_chk.c | 6 | ||||
-rw-r--r-- | debug/tst-chk1.c | 168 | ||||
-rw-r--r-- | debug/wcstombs_chk.c | 2 |
5 files changed, 86 insertions, 94 deletions
diff --git a/debug/mbsnrtowcs_chk.c b/debug/mbsnrtowcs_chk.c index 2041eac87f..8872540ee0 100644 --- a/debug/mbsnrtowcs_chk.c +++ b/debug/mbsnrtowcs_chk.c @@ -24,7 +24,7 @@ size_t __mbsnrtowcs_chk (wchar_t *dst, __const char **src, size_t nmc, size_t len, mbstate_t *ps, size_t dstlen) { - if (__builtin_expect (dstlen < len * sizeof (wchar_t), 0)) + if (__builtin_expect (dstlen < len, 0)) __chk_fail (); return __mbsnrtowcs (dst, src, nmc, len, ps); diff --git a/debug/mbsrtowcs_chk.c b/debug/mbsrtowcs_chk.c index fd4b3bf76b..22d5a35580 100644 --- a/debug/mbsrtowcs_chk.c +++ b/debug/mbsrtowcs_chk.c @@ -24,7 +24,7 @@ size_t __mbsrtowcs_chk (wchar_t *dst, __const char **src, size_t len, mbstate_t *ps, size_t dstlen) { - if (__builtin_expect (dstlen < len * sizeof (wchar_t), 0)) + if (__builtin_expect (dstlen < len, 0)) __chk_fail (); return __mbsrtowcs (dst, src, len, ps); diff --git a/debug/mbstowcs_chk.c b/debug/mbstowcs_chk.c index 2c1c3bb2c1..d1403c5d2b 100644 --- a/debug/mbstowcs_chk.c +++ b/debug/mbstowcs_chk.c @@ -22,14 +22,14 @@ size_t -__mbstowcs_chk (wchar_t *dst, const char **src, size_t len, size_t dstlen) +__mbstowcs_chk (wchar_t *dst, const char *src, size_t len, size_t dstlen) { - if (__builtin_expect (dstlen < len * sizeof (wchar_t), 0)) + if (__builtin_expect (dstlen < len, 0)) __chk_fail (); mbstate_t state; memset (&state, '\0', sizeof state); /* Return how many we wrote (or maybe an error). */ - return __mbsrtowcs (dst, src, len, &state); + return __mbsrtowcs (dst, &src, len, &state); } diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c index 8940e880e6..a47d1466ec 100644 --- a/debug/tst-chk1.c +++ b/debug/tst-chk1.c @@ -20,6 +20,7 @@ /* Hack: make sure GCC doesn't know __chk_fail () will not return. */ #define __noreturn__ +#include <assert.h> #include <fcntl.h> #include <locale.h> #include <paths.h> @@ -1033,23 +1034,27 @@ do_test (void) #if PATH_MAX > 0 char largebuf[PATH_MAX]; char *realres = realpath (".", largebuf); -#endif -#if __USE_FORTIFY_LEVEL >= 1 + if (realres != largebuf) + FAIL (); + +# if __USE_FORTIFY_LEVEL >= 1 CHK_FAIL_START char realbuf[1]; realres = realpath (".", realbuf); + if (realres != realbuf) + FAIL (); CHK_FAIL_END +# endif #endif if (setlocale (LC_ALL, "de_DE.UTF-8") != NULL) { + assert (MB_CUR_MAX <= 10); + /* First a simple test. */ - char enough[MB_CUR_MAX]; + char enough[10]; if (wctomb (enough, L'A') != 1) - { - puts ("first wctomb test failed"); - ret = 1; - } + FAIL (); #if __USE_FORTIFY_LEVEL >= 1 /* We know the wchar_t encoding is ISO 10646. So pick a @@ -1058,20 +1063,14 @@ do_test (void) CHK_FAIL_START char smallbuf[2]; if (wctomb (smallbuf, L'\x100') != 2) - { - puts ("second wctomb test failed"); - ret = 1; - } + FAIL (); CHK_FAIL_END #endif mbstate_t s; memset (&s, '\0', sizeof (s)); - if (wcrtomb (enough, L'A', &s) != 1) - { - puts ("first wcrtomb test failed"); - ret = 1; - } + if (wcrtomb (enough, L'D', &s) != 1 || enough[0] != 'D') + FAIL (); #if __USE_FORTIFY_LEVEL >= 1 /* We know the wchar_t encoding is ISO 10646. So pick a @@ -1080,26 +1079,23 @@ do_test (void) CHK_FAIL_START char smallbuf[2]; if (wcrtomb (smallbuf, L'\x100', &s) != 2) - { - puts ("second wcrtomb test failed"); - ret = 1; - } + FAIL (); CHK_FAIL_END #endif wchar_t wenough[10]; memset (&s, '\0', sizeof (s)); const char *cp = "A"; - if (mbsrtowcs (wenough, &cp, 10, &s) != 1) - { - puts ("first mbsrtowcs test failed"); - ret = 1; - } + if (mbsrtowcs (wenough, &cp, 10, &s) != 1 + || wcscmp (wenough, L"A") != 0) + FAIL (); + + cp = "BC"; + if (mbsrtowcs (wenough, &cp, l0 + 10, &s) != 2 + || wcscmp (wenough, L"BC") != 0) + FAIL (); #if __USE_FORTIFY_LEVEL >= 1 - /* We know the wchar_t encoding is ISO 10646. So pick a - character which has a multibyte representation which does not - fit. */ CHK_FAIL_START wchar_t wsmallbuf[2]; cp = "ABC"; @@ -1108,16 +1104,16 @@ do_test (void) #endif cp = "A"; - if (mbstowcs (wenough, cp, 10) != 1) - { - puts ("first mbstowcs test failed"); - ret = 1; - } + if (mbstowcs (wenough, cp, 10) != 1 + || wcscmp (wenough, L"A") != 0) + FAIL (); + + cp = "DEF"; + if (mbstowcs (wenough, cp, l0 + 10) != 3 + || wcscmp (wenough, L"DEF") != 0) + FAIL (); #if __USE_FORTIFY_LEVEL >= 1 - /* We know the wchar_t encoding is ISO 10646. So pick a - character which has a multibyte representation which does not - fit. */ CHK_FAIL_START wchar_t wsmallbuf[2]; cp = "ABC"; @@ -1126,17 +1122,18 @@ do_test (void) #endif memset (&s, '\0', sizeof (s)); - cp = "A"; - if (mbsnrtowcs (wenough, &cp, 1, 10, &s) != 1) - { - puts ("first mbsnrtowcs test failed"); - ret = 1; - } + cp = "ABC"; + wcscpy (wenough, L"DEF"); + if (mbsnrtowcs (wenough, &cp, 1, 10, &s) != 1 + || wcscmp (wenough, L"AEF") != 0) + FAIL (); + + cp = "IJ"; + if (mbsnrtowcs (wenough, &cp, 1, l0 + 10, &s) != 1 + || wcscmp (wenough, L"IEF") != 0) + FAIL (); #if __USE_FORTIFY_LEVEL >= 1 - /* We know the wchar_t encoding is ISO 10646. So pick a - character which has a multibyte representation which does not - fit. */ CHK_FAIL_START wchar_t wsmallbuf[2]; cp = "ABC"; @@ -1146,16 +1143,16 @@ do_test (void) memset (&s, '\0', sizeof (s)); const wchar_t *wcp = L"A"; - if (wcsrtombs (enough, &wcp, 10, &s) != 1) - { - puts ("first wcsrtombs test failed"); - ret = 1; - } + if (wcsrtombs (enough, &wcp, 10, &s) != 1 + || strcmp (enough, "A") != 0) + FAIL (); + + wcp = L"BC"; + if (wcsrtombs (enough, &wcp, l0 + 10, &s) != 2 + || strcmp (enough, "BC") != 0) + FAIL (); #if __USE_FORTIFY_LEVEL >= 1 - /* We know the wchar_t encoding is ISO 10646. So pick a - character which has a multibyte representation which does not - fit. */ CHK_FAIL_START char smallbuf[2]; wcp = L"ABC"; @@ -1163,17 +1160,18 @@ do_test (void) CHK_FAIL_END #endif - wcp = L"A"; - if (wcstombs (enough, wcp, 10) != 1) - { - puts ("first wcstombs test failed"); - ret = 1; - } + memset (enough, 'Z', sizeof (enough)); + wcp = L"EF"; + if (wcstombs (enough, wcp, 10) != 2 + || strcmp (enough, "EF") != 0) + FAIL (); + + wcp = L"G"; + if (wcstombs (enough, wcp, l0 + 10) != 1 + || strcmp (enough, "G") != 0) + FAIL (); #if __USE_FORTIFY_LEVEL >= 1 - /* We know the wchar_t encoding is ISO 10646. So pick a - character which has a multibyte representation which does not - fit. */ CHK_FAIL_START char smallbuf[2]; wcp = L"ABC"; @@ -1182,17 +1180,17 @@ do_test (void) #endif memset (&s, '\0', sizeof (s)); - wcp = L"A"; - if (wcsnrtombs (enough, &wcp, 1, 10, &s) != 1) - { - puts ("first wcsnrtombs test failed"); - ret = 1; - } + wcp = L"AB"; + if (wcsnrtombs (enough, &wcp, 1, 10, &s) != 1 + || strcmp (enough, "A") != 0) + FAIL (); + + wcp = L"BCD"; + if (wcsnrtombs (enough, &wcp, 1, l0 + 10, &s) != 1 + || strcmp (enough, "B") != 0) + FAIL (); #if __USE_FORTIFY_LEVEL >= 1 - /* We know the wchar_t encoding is ISO 10646. So pick a - character which has a multibyte representation which does not - fit. */ CHK_FAIL_START char smallbuf[2]; wcp = L"ABC"; @@ -1211,38 +1209,36 @@ do_test (void) { char enough[1000]; if (ptsname_r (fd, enough, sizeof (enough)) != 0) - { - puts ("first ptsname_r failed"); - ret = 1; - } + FAIL (); #if __USE_FORTIFY_LEVEL >= 1 CHK_FAIL_START char smallbuf[2]; if (ptsname_r (fd, smallbuf, sizeof (smallbuf) + 1) == 0) - { - puts ("second ptsname_r somehow suceeded"); - ret = 1; - } + FAIL (); CHK_FAIL_END #endif close (fd); } +#if PATH_MAX > 0 confstr (_CS_GNU_LIBC_VERSION, largebuf, sizeof (largebuf)); -#if __USE_FORTIFY_LEVEL >= 1 +# if __USE_FORTIFY_LEVEL >= 1 CHK_FAIL_START char smallbuf[1]; confstr (_CS_GNU_LIBC_VERSION, smallbuf, sizeof (largebuf)); CHK_FAIL_END +# endif #endif gid_t grpslarge[5]; int ngr = getgroups (5, grpslarge); + asm volatile ("" : : "r" (ngr)); #if __USE_FORTIFY_LEVEL >= 1 CHK_FAIL_START char smallbuf[1]; ngr = getgroups (5, (gid_t *) smallbuf); + asm volatile ("" : : "r" (ngr)); CHK_FAIL_END #endif @@ -1251,19 +1247,13 @@ do_test (void) { char enough[1000]; if (ttyname_r (fd, enough, sizeof (enough)) != 0) - { - puts ("first ttyname_r failed"); - ret = 1; - } + FAIL (); #if __USE_FORTIFY_LEVEL >= 1 CHK_FAIL_START char smallbuf[2]; if (ttyname_r (fd, smallbuf, sizeof (smallbuf) + 1) == 0) - { - puts ("second ttyname_r somehow suceeded"); - ret = 1; - } + FAIL (); CHK_FAIL_END #endif close (fd); @@ -1289,10 +1279,12 @@ do_test (void) char domainnamelarge[1000]; int res = getdomainname (domainnamelarge, sizeof (domainnamelarge)); + asm volatile ("" : : "r" (res)); #if __USE_FORTIFY_LEVEL >= 1 CHK_FAIL_START char smallbuf[1]; res = getdomainname (smallbuf, sizeof (domainnamelarge)); + asm volatile ("" : : "r" (res)); CHK_FAIL_END #endif diff --git a/debug/wcstombs_chk.c b/debug/wcstombs_chk.c index f5f51a0c11..0da48f9803 100644 --- a/debug/wcstombs_chk.c +++ b/debug/wcstombs_chk.c @@ -32,5 +32,5 @@ __wcstombs_chk (char *dst, __const wchar_t *src, size_t len, size_t dstlen) memset (&state, '\0', sizeof state); /* Return how many we wrote (or maybe an error). */ - return __wcsrtombs (dst, src, len, &state); + return __wcsrtombs (dst, &src, len, &state); } |