summary refs log tree commit diff
path: root/debug
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2022-06-21 14:43:30 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2022-10-28 11:15:28 +0100
commite5ece9de1417ac33c755226f3dd962fc2c7d97aa (patch)
tree72d9ba8fe793359b1ba5a8353d75e2c4d7439247 /debug
parent09c6c6073c925235b385af1d8edf6bc853eeaf60 (diff)
downloadglibc-e5ece9de1417ac33c755226f3dd962fc2c7d97aa.tar.gz
glibc-e5ece9de1417ac33c755226f3dd962fc2c7d97aa.tar.xz
glibc-e5ece9de1417ac33c755226f3dd962fc2c7d97aa.zip
Fix invalid pointer dereference in wcscpy_chk
The src pointer is const and points to a different object, so accessing
dest via src is invalid.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
Diffstat (limited to 'debug')
-rw-r--r--debug/wcscpy_chk.c34
1 files changed, 7 insertions, 27 deletions
diff --git a/debug/wcscpy_chk.c b/debug/wcscpy_chk.c
index 8ef03f81e4..d2dc769181 100644
--- a/debug/wcscpy_chk.c
+++ b/debug/wcscpy_chk.c
@@ -24,36 +24,16 @@ wchar_t *
 __wcscpy_chk (wchar_t *dest, const wchar_t *src, size_t n)
 {
   wint_t c;
-  wchar_t *wcp;
+  wchar_t *wcp = dest;
 
-  if (__alignof__ (wchar_t) >= sizeof (wchar_t))
+  do
     {
-      const ptrdiff_t off = dest - src - 1;
-
-      wcp = (wchar_t *) src;
-
-      do
-	{
-	  if (__glibc_unlikely (n-- == 0))
-	    __chk_fail ();
-	  c = *wcp++;
-	  wcp[off] = c;
-	}
-      while (c != L'\0');
-    }
-  else
-    {
-      wcp = dest;
-
-      do
-	{
-	  if (__glibc_unlikely (n-- == 0))
-	    __chk_fail ();
-	  c = *src++;
-	  *wcp++ = c;
-	}
-      while (c != L'\0');
+      if (__glibc_unlikely (n-- == 0))
+        __chk_fail ();
+      c = *src++;
+      *wcp++ = c;
     }
+  while (c != L'\0');
 
   return dest;
 }