summary refs log tree commit diff
path: root/debug
diff options
context:
space:
mode:
Diffstat (limited to 'debug')
-rw-r--r--debug/Makefile3
-rw-r--r--debug/Versions3
-rw-r--r--debug/mbsnrtowcs_chk.c31
-rw-r--r--debug/mbsrtowcs_chk.c31
-rw-r--r--debug/tst-chk1.c108
-rw-r--r--debug/wcrtomb_chk.c35
-rw-r--r--debug/wcsnrtombs_chk.c31
-rw-r--r--debug/wcsrtombs_chk.c31
8 files changed, 267 insertions, 6 deletions
diff --git a/debug/Makefile b/debug/Makefile
index e3fccc192e..009c05c9d9 100644
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -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
diff --git a/debug/Versions b/debug/Versions
index f33fbed6ef..2f4183bceb 100644
--- a/debug/Versions
+++ b/debug/Versions
@@ -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;
   }
diff --git a/debug/mbsnrtowcs_chk.c b/debug/mbsnrtowcs_chk.c
new file mode 100644
index 0000000000..2041eac87f
--- /dev/null
+++ b/debug/mbsnrtowcs_chk.c
@@ -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);
+}
diff --git a/debug/mbsrtowcs_chk.c b/debug/mbsrtowcs_chk.c
new file mode 100644
index 0000000000..fd4b3bf76b
--- /dev/null
+++ b/debug/mbsrtowcs_chk.c
@@ -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);
+}
diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c
index 47938bbf36..62b0fa6f40 100644
--- a/debug/tst-chk1.c
+++ b/debug/tst-chk1.c
@@ -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
     {
diff --git a/debug/wcrtomb_chk.c b/debug/wcrtomb_chk.c
new file mode 100644
index 0000000000..228430f373
--- /dev/null
+++ b/debug/wcrtomb_chk.c
@@ -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);
+}
diff --git a/debug/wcsnrtombs_chk.c b/debug/wcsnrtombs_chk.c
new file mode 100644
index 0000000000..67644bd557
--- /dev/null
+++ b/debug/wcsnrtombs_chk.c
@@ -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);
+}
diff --git a/debug/wcsrtombs_chk.c b/debug/wcsrtombs_chk.c
new file mode 100644
index 0000000000..9334267bae
--- /dev/null
+++ b/debug/wcsrtombs_chk.c
@@ -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);
+}