public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/arm/morello/main] cheri: Fix invalid pointer deref in wcscpy_chk
@ 2022-08-05 19:29 Szabolcs Nagy
  0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2022-08-05 19:29 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=dec33ea23fc0550aaa27e32d13ff4478b0b850d1

commit dec33ea23fc0550aaa27e32d13ff4478b0b850d1
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Tue Jun 21 14:43:30 2022 +0100

    cheri: Fix invalid pointer deref in wcscpy_chk
    
    The src pointer is const, accessing dest via it fails on CHERI targets.

Diff:
---
 debug/wcscpy_chk.c | 34 +++++++---------------------------
 1 file 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;
 }


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [glibc/arm/morello/main] cheri: Fix invalid pointer deref in wcscpy_chk
@ 2022-10-26 15:11 Szabolcs Nagy
  0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2022-10-26 15:11 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1f6055dcb036abdb3db0ea622e08c60966811127

commit 1f6055dcb036abdb3db0ea622e08c60966811127
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Tue Jun 21 14:43:30 2022 +0100

    cheri: Fix invalid pointer deref in wcscpy_chk
    
    The src pointer is const, accessing dest via it fails on CHERI targets.

Diff:
---
 debug/wcscpy_chk.c | 34 +++++++---------------------------
 1 file 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;
 }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-26 15:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-05 19:29 [glibc/arm/morello/main] cheri: Fix invalid pointer deref in wcscpy_chk Szabolcs Nagy
2022-10-26 15:11 Szabolcs Nagy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).