[PATCH 05/20] Fix invalid pointer dereference in wcscpy_chk

Florian Weimer fweimer@redhat.com
Fri Oct 28 05:34:53 GMT 2022


* Szabolcs Nagy via Libc-alpha:

> The src pointer is const and points to a different object, so accessing
> dest via src is invalid.
> ---
>  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 = dest;
>  
> +  do
>      {
> +      if (__glibc_unlikely (n-- == 0))
> +        __chk_fail ();
> +      c = *src++;
> +      *wcp++ = c;
>      }
> +  while (c != L'\0');
>  
>    return dest;
>  }

Seems fine.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Thanks,
Florian



More information about the Libc-alpha mailing list