<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/libosmo-sccp/+/16831">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  osmith: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">ss7: Improve checks in osmo_ss7_asp_peer_add_host()<br><br>* Introduce check to make sure we don't write out of peer->host bounds.<br>* Clean up any/specific address checks, it should be more clear now.<br><br>Change-Id: I3ecb94267acbec6ecf2134b08110f24f131cd8cf<br>---<br>M src/osmo_ss7.c<br>1 file changed, 17 insertions(+), 11 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c</span><br><span>index 70ec847..b7d69cb 100644</span><br><span>--- a/src/osmo_ss7.c</span><br><span>+++ b/src/osmo_ss7.c</span><br><span>@@ -1149,19 +1149,25 @@</span><br><span>        bool new_is_any = !host || !strcmp(host, "0.0.0.0");</span><br><span>       bool iter_is_any;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   /* Makes no sense to have INET_ANY and specific addresses in the set */</span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 0; i < peer->host_cnt; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">-                    iter_is_any = !peer->host[i] ||</span><br><span style="color: hsl(0, 100%, 40%);">-                                    !strcmp(peer->host[i], "0.0.0.0");</span><br><span style="color: hsl(0, 100%, 40%);">-                   if (new_is_any && iter_is_any)</span><br><span style="color: hsl(0, 100%, 40%);">-                          return -EINVAL;</span><br><span style="color: hsl(0, 100%, 40%);">-                 if (!new_is_any && iter_is_any)</span><br><span style="color: hsl(0, 100%, 40%);">-                         return -EINVAL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-       /* Makes no sense to have INET_ANY many times */</span><br><span style="color: hsl(0, 100%, 40%);">-        if (new_is_any && peer->host_cnt)</span><br><span style="color: hsl(120, 100%, 40%);">+  if (peer->host_cnt >= ARRAY_SIZE(peer->host))</span><br><span>               return -EINVAL;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+   /* Makes no sense to have INET_ANY many times, or INET_ANY together with</span><br><span style="color: hsl(120, 100%, 40%);">+         specific addresses: */</span><br><span style="color: hsl(120, 100%, 40%);">+     if (new_is_any && peer->host_cnt != 0)</span><br><span style="color: hsl(120, 100%, 40%);">+             return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Makes no sense to add specific address to set if INET_ANY is</span><br><span style="color: hsl(120, 100%, 40%);">+          already set: */</span><br><span style="color: hsl(120, 100%, 40%);">+    if (!new_is_any) {</span><br><span style="color: hsl(120, 100%, 40%);">+            for (i = 0; i < peer->host_cnt; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+                          iter_is_any = !peer->host[i] ||</span><br><span style="color: hsl(120, 100%, 40%);">+                                          !strcmp(peer->host[i], "0.0.0.0");</span><br><span style="color: hsl(120, 100%, 40%);">+                         if (iter_is_any)</span><br><span style="color: hsl(120, 100%, 40%);">+                                      return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+               }</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  osmo_talloc_replace_string(talloc_ctx, &peer->host[peer->host_cnt], host);</span><br><span>         peer->host_cnt++;</span><br><span>         return 0;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmo-sccp/+/16831">change 16831</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmo-sccp/+/16831"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmo-sccp </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I3ecb94267acbec6ecf2134b08110f24f131cd8cf </div>
<div style="display:none"> Gerrit-Change-Number: 16831 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: osmith <osmith@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>