[PATCH v3 3/3] getcwd: Set errno to ERANGE for size == 1 (CVE-2021-3999)

Adhemerval Zanella adhemerval.zanella@linaro.org
Fri Jan 21 17:31:34 GMT 2022



On 21/01/2022 14:26, Siddhesh Poyarekar wrote:
> On 21/01/2022 22:11, Adhemerval Zanella wrote:
>>
>>
>> On 20/01/2022 06:32, Siddhesh Poyarekar wrote:
>>> +  cmsg = CMSG_FIRSTHDR (&msg);
>>> +  if (cmsg == NULL)
>>> +    return -1;
>>> +  if (cmsg->cmsg_type != SCM_RIGHTS)
>>> +    return -1;
>>> +  fd = *(const int *) CMSG_DATA (cmsg);
>>
>> Same as before, I think you will need to copy to a temporary using memcpy.
> 
> Why not just:
> 
>     memcpy (&fd, CMSG_DATA (cmsg), sizeof (fd));
> 
> i.e., is a temporary necessary?

Not really, the above works just fine.


More information about the Libc-alpha mailing list