lkml.org 
[lkml]   [2011]   [Feb]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: af_unix unix_getname: return size for unnamed sockets too small?
Marcus Meissner <meissner@suse.de> writes:

> Hi,
>
> In net/unix/af_unix.c::unix_getname() there is a small problem:
>
> if (!u->addr) {
> sunaddr->sun_family = AF_UNIX;
> sunaddr->sun_path[0] = 0; // not copied out
> *uaddr_len = sizeof(short);
> } else {
> struct unix_address *addr = u->addr;
>
> *uaddr_len = addr->len;
> memcpy(sunaddr, addr->name, *uaddr_len);
> }
>
> The if (!u->addr) case will not copy out the \0 in the sun_path, as
> uaddr_len is just the size of sun_family.
>
> (Shown by socat crashing after decoding gethostname return and expected
> sun_path to be a valid string (and not seeing the \0)).

Perhaps my memory is scrambled but the sun_path has embedded '\0's so I
don't see how a correct application can expect the path to be '\0'
terminated. An application should be looking at the length we give it.

> Should it perhaps be *uaddr_len = sizeof(short)+sizeof(char)?

I don't think so.

Eric



\
 
 \ /
  Last update: 2011-02-02 20:01    [W:0.029 / U:8.540 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site