From 8f839fbc317aebd9cc893a62d981858d354e7ded Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Tue, 7 Mar 2017 11:02:11 +0000 Subject: [PATCH] posix: sockets: address was not set in recvfrom 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 --- sys/posix/sockets/posix_sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/posix/sockets/posix_sockets.c b/sys/posix/sockets/posix_sockets.c index da8d2d07a130..a291d2bf3930 100644 --- a/sys/posix/sockets/posix_sockets.c +++ b/sys/posix/sockets/posix_sockets.c @@ -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: