mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-24 14:00:30 +00:00
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>
This commit is contained in:
parent
09c6c6073c
commit
e5ece9de14
@ -24,26 +24,7 @@ wchar_t *
|
||||
__wcscpy_chk (wchar_t *dest, const wchar_t *src, size_t n)
|
||||
{
|
||||
wint_t c;
|
||||
wchar_t *wcp;
|
||||
|
||||
if (__alignof__ (wchar_t) >= sizeof (wchar_t))
|
||||
{
|
||||
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;
|
||||
wchar_t *wcp = dest;
|
||||
|
||||
do
|
||||
{
|
||||
@ -53,7 +34,6 @@ __wcscpy_chk (wchar_t *dest, const wchar_t *src, size_t n)
|
||||
*wcp++ = c;
|
||||
}
|
||||
while (c != L'\0');
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user