diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-04-02 01:40:29 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-04-02 01:40:29 +0200 |
commit | e8c1d0fe7cdfcbf0d913b5091a33a14da561f976 (patch) | |
tree | a04271094793b14bcd1bd5050afc7c90399b6fe7 /sys/src/ape/lib/bsd/accept.c | |
parent | e8a02760901e0b700ba845c9f57601f662e0e0aa (diff) |
ape: check *alen before copying in getpeername(), getsockname() and accept()
*alen has to be initialized to the size of the buffer
by the caller, and we are supposed to put the real
size of the address in there, but not copy more than
the original *alen value (truncate).
Diffstat (limited to 'sys/src/ape/lib/bsd/accept.c')
-rw-r--r-- | sys/src/ape/lib/bsd/accept.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/sys/src/ape/lib/bsd/accept.c b/sys/src/ape/lib/bsd/accept.c index 4f6203652..7a087c590 100644 --- a/sys/src/ape/lib/bsd/accept.c +++ b/sys/src/ape/lib/bsd/accept.c @@ -62,14 +62,8 @@ accept(int fd, void *a, int *alen) close(nfd); return -1; } - /* get remote address */ - _sock_ingetaddr(nr, &nr->raddr, &n, "remote"); - if(a != 0){ - if(n > 0) - memmove(a, &nr->raddr, n); - *alen = n; - } - return nfd; + _sock_ingetaddr(nr, &nr->raddr, 0, "remote"); + break; case PF_UNIX: if(r->other >= 0){ errno = EGREG; @@ -106,10 +100,15 @@ accept(int fd, void *a, int *alen) nr->domain = r->domain; nr->stype = r->stype; nr->protocol = r->protocol; - - return nfd; + nr->raddr = r->addr; + break; default: errno = EOPNOTSUPP; return -1; } + + if(a != 0) + getpeername(nfd, a, alen); + + return nfd; } |