From 542e045bba614e5081e2802b17529a1fa227dd7f Mon Sep 17 00:00:00 2001
From: Yonezawa-T2 <Yonezawa-T2@mail.dnp.co.jp>
Date: Tue, 8 Dec 2015 19:20:59 +0900
Subject: [PATCH] gnrc_ipv6_netif: fixed crash when ENABLE_DEBUG is 1.

When ENABLE_DEBUG is 1, `out` is dereferenced unconditionally, but
`_parse_options` in `gnrc_rpl_control_messages.c` calls it with NULL.

Clarified `out` must not NULL and fixed `_parse_options`.
---
 sys/include/net/gnrc/ipv6/netif.h                       | 2 ++
 sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c | 5 +----
 sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c    | 3 ++-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/sys/include/net/gnrc/ipv6/netif.h b/sys/include/net/gnrc/ipv6/netif.h
index 3385003f90..637a563dd4 100644
--- a/sys/include/net/gnrc/ipv6/netif.h
+++ b/sys/include/net/gnrc/ipv6/netif.h
@@ -484,6 +484,8 @@ ipv6_addr_t *gnrc_ipv6_netif_find_addr(kernel_pid_t pid, const ipv6_addr_t *addr
  *
  * @param[in] prefix    The prefix you want to search for.
  *
+ * @pre     @p out must not be NULL.
+ *
  * @return  The PID to the interface the address is registered to.
  * @return  KERNEL_PID_UNDEF, if no matching address can not be found on any
  *          interface.
diff --git a/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c b/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c
index 1fbcc47e8c..e927b21a44 100644
--- a/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c
+++ b/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c
@@ -502,10 +502,7 @@ kernel_pid_t gnrc_ipv6_netif_find_by_prefix(ipv6_addr_t **out, const ipv6_addr_t
         match = _find_by_prefix_unsafe(&tmp_res, ipv6_ifs + i, prefix, NULL);
 
         if (match > best_match) {
-            if (out != NULL) {
-                *out = tmp_res;
-            }
-
+            *out = tmp_res;
             res = ipv6_ifs[i].pid;
             best_match = match;
         }
diff --git a/sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c b/sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c
index 297ec132c9..39eefa25be 100644
--- a/sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c
+++ b/sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c
@@ -430,7 +430,8 @@ bool _parse_options(int msg_type, gnrc_rpl_instance_t *inst, gnrc_rpl_opt_t *opt
             case (GNRC_RPL_OPT_TARGET):
                 DEBUG("RPL: RPL TARGET DAO option parsed\n");
                 *included_opts |= ((uint32_t) 1) << GNRC_RPL_OPT_TARGET;
-                if_id = gnrc_ipv6_netif_find_by_prefix(NULL, &dodag->dodag_id);
+                ipv6_addr_t *prefix = NULL;
+                if_id = gnrc_ipv6_netif_find_by_prefix(&prefix, &dodag->dodag_id);
                 if (if_id == KERNEL_PID_UNDEF) {
                     DEBUG("RPL: no interface found for the configured DODAG id\n");
                     return false;
-- 
GitLab