public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Szabolcs Nagy <nsz@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] Fix invalid pointer dereference in wcscpy_chk Date: Fri, 28 Oct 2022 10:18:27 +0000 (GMT) [thread overview] Message-ID: <20221028101827.88C7A3857001@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e5ece9de1417ac33c755226f3dd962fc2c7d97aa commit e5ece9de1417ac33c755226f3dd962fc2c7d97aa Author: Szabolcs Nagy <szabolcs.nagy@arm.com> Date: Tue Jun 21 14:43:30 2022 +0100 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> 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; }
reply other threads:[~2022-10-28 10:18 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221028101827.88C7A3857001@sourceware.org \ --to=nsz@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).