From ce0d81c5c82fd022efe565ad02e5566dd2c0691e Mon Sep 17 00:00:00 2001
From: Martine Lenders <m.lenders@fu-berlin.de>
Date: Mon, 12 Jun 2017 13:53:11 +0200
Subject: [PATCH] sock: specify invalid parameter error

---
 sys/include/net/sock/ip.h     | 2 ++
 sys/include/net/sock/udp.h    | 2 ++
 sys/net/gnrc/sock/gnrc_sock.c | 5 ++++-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/sys/include/net/sock/ip.h b/sys/include/net/sock/ip.h
index 4ef4cf7053..17950625d3 100644
--- a/sys/include/net/sock/ip.h
+++ b/sys/include/net/sock/ip.h
@@ -403,6 +403,8 @@ int sock_ip_get_remote(sock_ip_t *sock, sock_ip_ep_t *ep);
  * @return  0, if no received data is available, but everything is in order.
  * @return  -EADDRNOTAVAIL, if local of @p sock is not given.
  * @return  -EAGAIN, if @p timeout is `0` and no data is available.
+ * @return  -EINVAL, if @p remote is invalid or @p sock is not properly
+ *          initialized (or closed while sock_ip_recv() blocks).
  * @return  -ENOBUFS, if buffer space is not large enough to store received
  *          data.
  * @return  -ENOMEM, if no memory was available to receive @p data.
diff --git a/sys/include/net/sock/udp.h b/sys/include/net/sock/udp.h
index 39cad61945..82136a1552 100644
--- a/sys/include/net/sock/udp.h
+++ b/sys/include/net/sock/udp.h
@@ -389,6 +389,8 @@ int sock_udp_get_remote(sock_udp_t *sock, sock_udp_ep_t *ep);
  * @return  0, if no received data is available, but everything is in order.
  * @return  -EADDRNOTAVAIL, if local of @p sock is not given.
  * @return  -EAGAIN, if @p timeout is `0` and no data is available.
+ * @return  -EINVAL, if @p remote is invalid or @p sock is not properly
+ *          initialized (or closed while sock_udp_recv() blocks).
  * @return  -ENOBUFS, if buffer space is not large enough to store received
  *          data.
  * @return  -ENOMEM, if no memory was available to receive @p data.
diff --git a/sys/net/gnrc/sock/gnrc_sock.c b/sys/net/gnrc/sock/gnrc_sock.c
index 8b81758c07..84207bf344 100644
--- a/sys/net/gnrc/sock/gnrc_sock.c
+++ b/sys/net/gnrc/sock/gnrc_sock.c
@@ -57,6 +57,9 @@ ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt_out,
     gnrc_pktsnip_t *pkt, *ip, *netif;
     msg_t msg;
 
+    if (reg->mbox.cib.mask != (SOCK_MBOX_SIZE - 1)) {
+        return -EINVAL;
+    }
 #ifdef MODULE_XTIMER
     xtimer_t timeout_timer;
 
@@ -88,7 +91,7 @@ ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt_out,
             }
 #endif
         default:
-            return -EINTR;
+            return -EINVAL;
     }
     /* TODO: discern NETTYPE from remote->family (set in caller), when IPv4
      * was implemented */
-- 
GitLab