Skip to content

Commit

Permalink
posix: sockets: address was not set in recvfrom
Browse files Browse the repository at this point in the history
The address is an optional parameter of recvfrom. If it is
not null, recvfrom must store the address of the sender.
However this was only allowed if res was equal to 0, which
is wrong since res contains the number of bytes received
or -1.
This commit ensures that the address is set only if no
previous errors happened before.

Signed-off-by: Francois Berder <francois.berder@imgtec.com>
  • Loading branch information
francois-berder committed Mar 7, 2017
1 parent 2936a69 commit 8f839fb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sys/posix/sockets/posix_sockets.c
Expand Up @@ -826,7 +826,7 @@ ssize_t recvfrom(int socket, void *restrict buffer, size_t length, int flags,
res = -1;
break;
}
if ((res == 0) && (address != NULL) && (address_len != 0)) {
if ((res >= 0) && (address != NULL) && (address_len != 0)) {
switch (s->type) {
#ifdef MODULE_SOCK_TCP
case SOCK_STREAM:
Expand Down

0 comments on commit 8f839fb

Please sign in to comment.