From 43c2c728c9b9a534f2caea22fb42b86f1d232a10 Mon Sep 17 00:00:00 2001
From: Martine Lenders <m.lenders@fu-berlin.de>
Date: Tue, 5 Feb 2019 15:18:52 +0100
Subject: [PATCH] gnrc_sixlowpan_iphc: fix _compressible()

When either `gnrc_sixlowpan_iphc_nhc` or `gnrc_udp` is not compiled
in `_compressible()` never returns `true`. This causes the
`dispatch` snip in `gnrc_sixlowpan_iphc_send()` to be of length 0,
meaning `dispatch->data` is `NULL`, causing possible crashes when
trying to send IPv6 packets over 6LoWPAN without NHC or UDP.
---
 .../gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c  | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/net/gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c b/sys/net/gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c
index 85dada40c8..a4e0e96eae 100644
--- a/sys/net/gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c
+++ b/sys/net/gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c
@@ -647,8 +647,8 @@ static inline bool _compressible(gnrc_pktsnip_t *hdr)
         case GNRC_NETTYPE_IPV6:
 #if defined(MODULE_GNRC_SIXLOWPAN_IPHC_NHC) && defined(MODULE_GNRC_UDP)
         case GNRC_NETTYPE_UDP:
-            return true;
 #endif
+            return true;
         default:
             return false;
     }
@@ -705,6 +705,9 @@ void gnrc_sixlowpan_iphc_send(gnrc_pktsnip_t *pkt, void *ctx, unsigned page)
         dispatch = ptr; /* use dispatch as temporary point for prev */
         ptr = ptr->next;
     }
+    /* there should be at least one compressible header in `pkt`, otherwise this
+     * function should not be called */
+    assert(dispatch_size > 0);
     ipv6_hdr = pkt->next->data;
     dispatch = gnrc_pktbuf_add(NULL, NULL, dispatch_size,
                                GNRC_NETTYPE_SIXLOWPAN);
-- 
GitLab