1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

* wcsmbs/bits/wchar2.h: Add definitions for wcrtomb, mbsrtowcs,

wcsrtombs, mbsnrtowcs, and wcsnrtombs.
	* debug/Makefile (routines): Add wcrtomb_chk, mbsrtowcs_chk,
	wcsrtombs_chk, mbsnrtowcs_chk, and wcsnrtombs_chk.
	* debug/Versions: Add __wcrtomb_chk, __mbsrtowcs_chk,
	__wcsrtombs_chk, __mbsnrtowcs_chk, and __wcsnrtombs_chk.
	* debug/tst-chk1.c: Add tests for new functions.
	* debug/mbsnrtowcs_chk.c: New file.
	* debug/mbsrtowcs_chk.c: New file.
	* debug/wcrtomb_chk.c: New file.
	* debug/wcsnrtombs_chk.c: New file.
	* debug/wcsrtombs_chk.c: New file.

	* include/stdio.h: Add declaration for __fxprintf.
This commit is contained in:
Ulrich Drepper
2005-07-20 07:43:27 +00:00
parent 10ffcd52f0
commit df6f89692f
37 changed files with 582 additions and 509 deletions

View File

@@ -38,7 +38,8 @@ routines = backtrace backtracesyms backtracesymsfd noophooks \
swprintf_chk vswprintf_chk wprintf_chk fwprintf_chk \
vwprintf_chk vfwprintf_chk fgetws_chk fgetws_u_chk \
confstr_chk getgroups_chk ttyname_r_chk getlogin_r_chk \
gethostname_chk getdomainname_chk \
gethostname_chk getdomainname_chk wcrtomb_chk mbsnrtowcs_chk \
wcsnrtombs_chk mbsrtowcs_chk wcsrtombs_chk \
stack_chk_fail \
$(static-only-routines)
static-only-routines := warning-nop stack_chk_fail_local

View File

@@ -30,7 +30,8 @@ libc {
__swprintf_chk; __vswprintf_chk; __wprintf_chk; __fwprintf_chk;
__vwprintf_chk; __vfwprintf_chk; __fgetws_chk; __fgetws_unlocked_chk;
__confstr_chk; __getgroups_chk; __ttyname_r_chk; __getlogin_r_chk;
__gethostname_chk; __getdomainname_chk;
__gethostname_chk; __getdomainname_chk; __wcrtomb_chk; __mbsnrtowcs_chk;
__wcsnrtombs_chk; __mbsrtowcs_chk; __wcsrtombs_chk;
__stack_chk_fail;
}

31
debug/mbsnrtowcs_chk.c Normal file
View File

@@ -0,0 +1,31 @@
/* Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <locale.h>
#include <wchar.h>
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))
__chk_fail ();
return __mbsnrtowcs (dst, src, nmc, len, ps);
}

31
debug/mbsrtowcs_chk.c Normal file
View File

@@ -0,0 +1,31 @@
/* Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <locale.h>
#include <wchar.h>
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))
__chk_fail ();
return __mbsrtowcs (dst, src, len, ps);
}

View File

@@ -76,6 +76,7 @@ char buf[10];
wchar_t wbuf[10];
volatile size_t l0;
volatile char *p;
volatile wchar_t *wp;
const char *str1 = "JIHGFEDCBA";
const char *str2 = "F";
const char *str3 = "%s%n%s%n";
@@ -502,7 +503,7 @@ do_test (void)
CHK_FAIL_END
CHK_FAIL_START
p = wmempcpy (wbuf + 6, L"abcde", l0 + 5);
wp = wmempcpy (wbuf + 6, L"abcde", l0 + 5);
CHK_FAIL_END
CHK_FAIL_START
@@ -514,7 +515,7 @@ do_test (void)
CHK_FAIL_END
CHK_FAIL_START
p = wcpcpy (wbuf + 9, wstr2);
wp = wcpcpy (wbuf + 9, wstr2);
CHK_FAIL_END
CHK_FAIL_START
@@ -544,7 +545,7 @@ do_test (void)
CHK_FAIL_END
CHK_FAIL_START
p = wmempcpy (wa.buf1 + 6, L"abcde", l0 + 5);
wp = wmempcpy (wa.buf1 + 6, L"abcde", l0 + 5);
CHK_FAIL_END
CHK_FAIL_START
@@ -562,7 +563,7 @@ do_test (void)
CHK_FAIL_END
CHK_FAIL_START
p = wcpcpy (wa.buf1 + (O + 8), wstr2);
wp = wcpcpy (wa.buf1 + (O + 8), wstr2);
CHK_FAIL_END
CHK_FAIL_START
@@ -1056,6 +1057,105 @@ do_test (void)
}
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 __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];
if (wcrtomb (smallbuf, L'\x100', &s) != 2)
{
puts ("second wcrtomb test failed");
ret = 1;
}
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 __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";
mbsrtowcs (wsmallbuf, &cp, 10, &s);
CHK_FAIL_END
#endif
memset (&s, '\0', sizeof (s));
cp = "A";
if (mbsnrtowcs (wenough, &cp, 1, 10, &s) != 1)
{
puts ("first mbsnrtowcs test failed");
ret = 1;
}
#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";
mbsnrtowcs (wsmallbuf, &cp, 3, 10, &s);
CHK_FAIL_END
#endif
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 __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";
wcsrtombs (smallbuf, &wcp, 10, &s);
CHK_FAIL_END
#endif
memset (&s, '\0', sizeof (s));
wcp = L"A";
if (wcsnrtombs (enough, &wcp, 1, 10, &s) != 1)
{
puts ("first wcsnrtombs test failed");
ret = 1;
}
#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";
wcsnrtombs (smallbuf, &wcp, 3, 10, &s);
CHK_FAIL_END
#endif
}
else
{

35
debug/wcrtomb_chk.c Normal file
View File

@@ -0,0 +1,35 @@
/* Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <langinfo.h>
#include <locale.h>
#include <stdlib.h>
#include <wchar.h>
#include <locale/localeinfo.h>
size_t
__wcrtomb_chk (char *s, wchar_t wchar, mbstate_t *ps, size_t buflen)
{
/* We do not have to implement the full wctomb semantics since we
know that S cannot be NULL when we come here. */
if (buflen < MB_CUR_MAX)
__chk_fail ();
return __wcrtomb (s, wchar, ps);
}

31
debug/wcsnrtombs_chk.c Normal file
View File

@@ -0,0 +1,31 @@
/* Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <locale.h>
#include <wchar.h>
size_t
__wcsnrtombs_chk (char *dst, __const wchar_t **src, size_t nwc, size_t len,
mbstate_t *ps, size_t dstlen)
{
if (__builtin_expect (dstlen < len, 0))
__chk_fail ();
return __wcsnrtombs (dst, src, nwc, len, ps);
}

31
debug/wcsrtombs_chk.c Normal file
View File

@@ -0,0 +1,31 @@
/* Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <locale.h>
#include <wchar.h>
size_t
__wcsrtombs_chk (char *dst, __const wchar_t **src, size_t len,
mbstate_t *ps, size_t dstlen)
{
if (__builtin_expect (dstlen < len, 0))
__chk_fail ();
return __wcsrtombs (dst, src, len, ps);
}