[PATCH 3/3] getcwd: Set errno to ERANGE for size == 1 (CVE-2021-3999)
Andreas Schwab
schwab@linux-m68k.org
Tue Jan 18 11:52:21 GMT 2022
On Jan 18 2022, Siddhesh Poyarekar via Libc-alpha wrote:
> diff --git a/sysdeps/unix/sysv/linux/getcwd.c b/sysdeps/unix/sysv/linux/getcwd.c
> index a6b5a7e8b0..5ff678d674 100644
> --- a/sysdeps/unix/sysv/linux/getcwd.c
> +++ b/sysdeps/unix/sysv/linux/getcwd.c
> @@ -50,6 +50,13 @@ __getcwd (char *buf, size_t size)
> char *path;
> char *result;
>
> + /* A size of 1 byte is never useful. */
> + if (size == 1)
> + {
> + __set_errno (ERANGE);
> + return NULL;
> + }
> +
This is not needed, since the getcwd syscall does the check already and
returns the correct error.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
More information about the Libc-alpha
mailing list