From cbe231a1497ea38712fc40b287b634a23b3bc621 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 24 Apr 2015 19:37:05 +0200 Subject: [PATCH] [SQUASH ME] ng_sixlowpan_iphc: more error fixes --- .../ng_sixlowpan/iphc/ng_sixlowpan_iphc.c | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/sys/net/network_layer/ng_sixlowpan/iphc/ng_sixlowpan_iphc.c b/sys/net/network_layer/ng_sixlowpan/iphc/ng_sixlowpan_iphc.c index 41a9e76793b7..bcfcb7b7d2fe 100644 --- a/sys/net/network_layer/ng_sixlowpan/iphc/ng_sixlowpan_iphc.c +++ b/sys/net/network_layer/ng_sixlowpan/iphc/ng_sixlowpan_iphc.c @@ -120,7 +120,7 @@ bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt) ng_ipv6_hdr_t *ipv6_hdr; uint8_t *iphc_hdr = pkt->data; uint16_t payload_offset = NG_SIXLOWPAN_IPHC_HDR_LEN; - ng_sixlowpan_ctx_t *ctx; + ng_sixlowpan_ctx_t *ctx = NULL; ng_pktsnip_t *payload; ng_pktsnip_t *ipv6 = ng_pktbuf_add(NULL, NULL, sizeof(ng_ipv6_hdr_t), NG_NETTYPE_IPV6); @@ -192,14 +192,14 @@ bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt) if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_CID_EXT) { sci = iphc_hdr[CID_EXT_IDX] >> 4; + } - if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_SAM) { - ctx = ng_sixlowpan_ctx_lookup_id(sci); + if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_SAM) { + ctx = ng_sixlowpan_ctx_lookup_id(sci); - if (ctx == NULL) { - DEBUG("6lo iphc: could not find source context\n"); - return false; - } + if (ctx == NULL) { + DEBUG("6lo iphc: could not find source context\n"); + return false; } } } @@ -264,23 +264,23 @@ bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt) if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_CID_EXT) { dci = iphc_hdr[CID_EXT_IDX] & 0x0f; + } - if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_DAM) { - ctx = ng_sixlowpan_ctx_lookup_id(dci); + if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_DAM) { + ctx = ng_sixlowpan_ctx_lookup_id(dci); - if (ctx == NULL) { - DEBUG("6lo iphc: could not find destination context\n"); - return false; - } + if (ctx == NULL) { + DEBUG("6lo iphc: could not find destination context\n"); + return false; } } } - switch (iphc_hdr[IPHC2_IDX] & (NG_SIXLOWPAN_IPHC2_M |NG_SIXLOWPAN_IPHC2_DAC | + switch (iphc_hdr[IPHC2_IDX] & (NG_SIXLOWPAN_IPHC2_M | NG_SIXLOWPAN_IPHC2_DAC | NG_SIXLOWPAN_IPHC2_DAM)) { case IPHC_M_DAC_DAM_U_FULL: case IPHC_M_DAC_DAM_M_FULL: - memcpy(&(ipv6_hdr->dst.u8), iphc_hdr + payload, 16); + memcpy(&(ipv6_hdr->dst.u8), iphc_hdr + payload_offset, 16); payload_offset += 16; break; @@ -362,6 +362,7 @@ bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt) uint8_t orig_ctx_len = ctx->prefix_len; ng_ipv6_addr_set_unspecified(&ipv6_hdr->dst); + if (ctx->prefix_len > 64) { ctx->prefix_len = 64; } @@ -397,6 +398,8 @@ bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt) /* insert IPv6 header */ ipv6->next = pkt->next; pkt->next = ipv6; + + return true; } bool ng_sixlowpan_iphc_encode(ng_pktsnip_t *pkt)