[ic] vlink MINIVEND_SOCKET patch

Jon Jensen jon at endpoint.com
Tue May 5 16:58:29 UTC 2020


On Tue, 5 May 2020, David Christensen wrote:

>> +  strncpy(sa.sun_path, lsocket, sizeof(sa.sun_path) - 1);
>
> A couple of questions: is the sa struct guaranteed to be zero’d, so we 
> don’t need to worry about a NULL terminator (i.e., why there’s a -1 in 
> sizeof call)?

Using 1 byte smaller than sizeof, strncpy() guarantees null termination, 
because it clears the rest of the buffer, so it will have at least one 
null at the end.

> Also, if strlen(lsocket) > sizeof(sa.sun_path), a truncated copy would 
> end up being bunko, since it won’t refer to an actual valid path; would 
> it be better to just check if strlen(lsocket) > sizeof(sa.sun_path) -1 
> and error out if so?

Great point. No reason to proceed if the filename will be truncated.

Jon



-- 
Jon Jensen
End Point Corporation
https://www.endpoint.com/


More information about the interchange-users mailing list