From b9ca8f466f56769baf0dd6e1f53ac116183ee9ce Mon Sep 17 00:00:00 2001
From: smlng <s@mlng.net>
Date: Fri, 4 May 2018 11:08:48 +0200
Subject: [PATCH] gcoap: add asserts for path in gcoap_req_init

---
 sys/include/net/gcoap.h                 | 3 +++
 sys/net/application_layer/gcoap/gcoap.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/sys/include/net/gcoap.h b/sys/include/net/gcoap.h
index 6db480d96a..b3054b8c78 100644
--- a/sys/include/net/gcoap.h
+++ b/sys/include/net/gcoap.h
@@ -506,6 +506,9 @@ void gcoap_register_listener(gcoap_listener_t *listener);
  * @param[in] code      Request code: GCOAP_[GET|POST|PUT|DELETE]
  * @param[in] path      Resource path, *must* start with '/'
  *
+ * @pre @p path not `NULL`
+ * @pre @p path must start with `/`
+ *
  * @return  0 on success
  * @return  < 0 on error
  */
diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c
index 217c1bdcdb..630df36848 100644
--- a/sys/net/application_layer/gcoap/gcoap.c
+++ b/sys/net/application_layer/gcoap/gcoap.c
@@ -22,6 +22,7 @@
 #include <stdint.h>
 #include <stdatomic.h>
 
+#include "assert.h"
 #include "net/gcoap.h"
 #include "mutex.h"
 #include "random.h"
@@ -718,6 +719,8 @@ void gcoap_register_listener(gcoap_listener_t *listener)
 int gcoap_req_init(coap_pkt_t *pdu, uint8_t *buf, size_t len,
                    unsigned code, const char *path)
 {
+    assert((path != NULL) && (path[0] == '/'));
+
     (void)len;
 
     pdu->hdr = (coap_hdr_t *)buf;
-- 
GitLab