<h3>Contribution description</h3>
<p>According to the documentation of <code>gnrc_ipv6_nib_get_next_hop_l2addr()</code> <code>pkt</code> may be <code>NULL</code>. However, whenever that function sends an error message (the methods for that require <code>orig_pkt</code> not to be NULL) <code>pkt</code> is not checked, which may lead to failed assertions.</p>

<h3>Testing procedure</h3>

<h3>Issues/PRs references</h3>
<p>Compile and flash <code>tests/gnrc_ipv6_nib</code> with <code>USEMODULE=gnrc_icmpv6_error</code></p>
<pre><code>USEMODULE=gnrc_icmpv6_error make flash
</code></pre>
<p>and run the test</p>
<pre><code>make test
</code></pre>
<p>Without this fix the test will fail on an assertion at</p>
<p><div class="border rounded-1 my-2">
  <div class="f6 px-3 py-2 lh-condensed border-bottom bg-gray-light">
    <p class="mb-0 text-bold">
      <a href="https://github.com/RIOT-OS/RIOT/blob/94a10e9e103af972bd9edf9cdd1d2fa3c1300454/sys/net/gnrc/network_layer/icmpv6/error/gnrc_icmpv6_error.c#L244">RIOT/sys/net/gnrc/network_layer/icmpv6/error/gnrc_icmpv6_error.c</a>
    </p>
    <p class="mb-0 text-gray-light">
         Line 244
      in
      <a data-pjax="true" class="commit-tease-sha" href="/RIOT-OS/RIOT/commit/94a10e9e103af972bd9edf9cdd1d2fa3c1300454">94a10e9</a>
    </p>
    </div>
    <div itemprop="text" class="blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8">

        <tbody><tr class="border-0">
          <td id="L244" class="blob-num border-0 px-3 py-0 bg-white js-line-number" data-line-number="244"></td>
          <td id="LC244" class="blob-code border-0 px-3 py-0 bg-white blob-code-inner js-file-line"> <span class="pl-c1">assert</span>(ipv6 != <span class="pl-c1">NULL</span>); </td>
        </tr>
    </tbody></table>
  </div>
</div>
</p>
<p>With this fix the tests will pass.</p>
<h3>Issues/PRs references</h3>
<p>Discovered while debugging <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="414640378" data-permission-text="Issue title is private" data-url="https://github.com/RIOT-OS/RIOT/issues/11068" data-hovercard-type="pull_request" data-hovercard-url="/RIOT-OS/RIOT/pull/11068/hovercard" href="https://github.com/RIOT-OS/RIOT/pull/11068">#11068</a> where I use <code>gnrc_ipv6_nib_get_next_hop_l2addr()</code> with <code>pkt == NULL</code></p>
<p><div class="border rounded-1 my-2">
  <div class="f6 px-3 py-2 lh-condensed border-bottom bg-gray-light">
    <p class="mb-0 text-bold">
      <a href="https://github.com/RIOT-OS/RIOT/blob/a235f613c107f3efcf92a5c8adbeddd957a9ad0f/sys/net/gnrc/network_layer/sixlowpan/frag/minfwd/gnrc_sixlowpan_frag_minfwd.c#L51-L54">RIOT/sys/net/gnrc/network_layer/sixlowpan/frag/minfwd/gnrc_sixlowpan_frag_minfwd.c</a>
    </p>
    <p class="mb-0 text-gray-light">
        Lines 51 to 54
      in
      <a data-pjax="true" class="commit-tease-sha" href="/RIOT-OS/RIOT/commit/a235f613c107f3efcf92a5c8adbeddd957a9ad0f">a235f61</a>
    </p>
    </div>
    <div itemprop="text" class="blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8">

        <tbody><tr class="border-0">
          <td id="L51" class="blob-num border-0 px-3 py-0 bg-white js-line-number" data-line-number="51"></td>
          <td id="LC51" class="blob-code border-0 px-3 py-0 bg-white blob-code-inner js-file-line"> <span class="pl-k">if</span> (!<span class="pl-c1">ipv6_addr_is_link_local</span>(addr) && </td>
        </tr>

        <tr class="border-0">
          <td id="L52" class="blob-num border-0 px-3 py-0 bg-white js-line-number" data-line-number="52"></td>
          <td id="LC52" class="blob-code border-0 px-3 py-0 bg-white blob-code-inner js-file-line">     (<span class="pl-c1">gnrc_netif_get_by_ipv6_addr</span>(addr) == <span class="pl-c1">NULL</span>) && </td>
        </tr>

        <tr class="border-0">
          <td id="L53" class="blob-num border-0 px-3 py-0 bg-white js-line-number" data-line-number="53"></td>
          <td id="LC53" class="blob-code border-0 px-3 py-0 bg-white blob-code-inner js-file-line">     (<span class="pl-c1">gnrc_ipv6_nib_get_next_hop_l2addr</span>(addr, netif, <span class="pl-c1">NULL</span>, </td>
        </tr>

        <tr class="border-0">
          <td id="L54" class="blob-num border-0 px-3 py-0 bg-white js-line-number" data-line-number="54"></td>
          <td id="LC54" class="blob-code border-0 px-3 py-0 bg-white blob-code-inner js-file-line">                                        &nce) == <span class="pl-c1">0</span>)) { </td>
        </tr>
    </tbody></table>
  </div>
</div>
</p>


<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/RIOT-OS/RIOT/pull/11182'>https://github.com/RIOT-OS/RIOT/pull/11182</a></p>

<h4>Commit Summary</h4>
<ul>
  <li>gnrc_ipv6_nib: check if pkt is NULL on error</li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/11182/files#diff-0">sys/net/gnrc/network_layer/ipv6/nib/nib.c</a>
    (13)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/RIOT-OS/RIOT/pull/11182.patch'>https://github.com/RIOT-OS/RIOT/pull/11182.patch</a></li>
  <li><a href='https://github.com/RIOT-OS/RIOT/pull/11182.diff'>https://github.com/RIOT-OS/RIOT/pull/11182.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/RIOT-OS/RIOT/pull/11182">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AEn7YOJEwldFD2CxWHdaiJFrWGXS6Vbiks5vWlEMgaJpZM4b0KuR">mute the thread</a>.<img src="https://github.com/notifications/beacon/AEn7YF7Djm-1UW9-umT4mgIJUBNBMQFAks5vWlEMgaJpZM4b0KuR.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/RIOT-OS/RIOT","title":"RIOT-OS/RIOT","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/RIOT-OS/RIOT"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"gnrc_ipv6_nib: check if pkt is NULL on error (#11182)"}],"action":{"name":"View Pull Request","url":"https://github.com/RIOT-OS/RIOT/pull/11182"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/RIOT-OS/RIOT/pull/11182",
"url": "https://github.com/RIOT-OS/RIOT/pull/11182",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>