<p>dexter has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/13307">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">a_iface_bssap: check bssamp length field<br><br>At the moment the length field of the bssmap header is not parsed.<br>Instead the length is computed out of the known header length and the<br>number of bytes received. This is prone to error, lets make sure that<br>extranous data at the end of a message is ignored by parsing the bssmap<br>length correctly.<br><br>Change-Id: I3b89dd5a66ec83b03860b58b6b8eb58007f433a4<br>Related: OS#3806<br>---<br>M src/libmsc/a_iface_bssap.c<br>1 file changed, 28 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/07/13307/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/libmsc/a_iface_bssap.c b/src/libmsc/a_iface_bssap.c</span><br><span>index cb245b8..d0594bf 100644</span><br><span>--- a/src/libmsc/a_iface_bssap.c</span><br><span>+++ b/src/libmsc/a_iface_bssap.c</span><br><span>@@ -703,6 +703,33 @@</span><br><span>     return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Extract and verify the length information from the BSSMAP header. */</span><br><span style="color: hsl(120, 100%, 40%);">+void bssmap_msg_verify_len(struct msgb *msg)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  unsigned int expected_len;</span><br><span style="color: hsl(120, 100%, 40%);">+    unsigned int calculated_len;</span><br><span style="color: hsl(120, 100%, 40%);">+  struct bssmap_header *bssmap_header;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        bssmap_header = (struct bssmap_header *)msg->l2h;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        calculated_len = msgb_l3len(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+     expected_len = bssmap_header->length;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    /* In case of contradictory length information, decide for the</span><br><span style="color: hsl(120, 100%, 40%);">+         * shorter length */</span><br><span style="color: hsl(120, 100%, 40%);">+  if (calculated_len > expected_len) {</span><br><span style="color: hsl(120, 100%, 40%);">+               LOGP(DBSSAP, LOGL_NOTICE,</span><br><span style="color: hsl(120, 100%, 40%);">+                  "BSSMAP message contains extranous data, expected %u bytes, got %u bytes, truncated\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                     expected_len, calculated_len);</span><br><span style="color: hsl(120, 100%, 40%);">+           msgb_l3trim(msg, expected_len);</span><br><span style="color: hsl(120, 100%, 40%);">+       } else if (calculated_len < expected_len) {</span><br><span style="color: hsl(120, 100%, 40%);">+                LOGP(DMSC, LOGL_NOTICE,</span><br><span style="color: hsl(120, 100%, 40%);">+                    "Short BSSMAP message, expected %u bytes, got %u bytes\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                  expected_len, calculated_len);</span><br><span style="color: hsl(120, 100%, 40%);">+           msgb_l3trim(msg, calculated_len);</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> /* Handle incoming connection oriented messages. No ownership of 'msg' is passed on! */</span><br><span> int a_sccp_rx_dt(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg)</span><br><span> {</span><br><span>@@ -718,6 +745,7 @@</span><br><span>        switch (msg->l2h[0]) {</span><br><span>    case BSSAP_MSG_BSS_MANAGEMENT:</span><br><span>               msg->l3h = &msg->l2h[sizeof(struct bssmap_header)];</span><br><span style="color: hsl(120, 100%, 40%);">+         bssmap_msg_verify_len(msg);</span><br><span>          return rx_bssmap(scu, a_conn_info, msg);</span><br><span>     case BSSAP_MSG_DTAP:</span><br><span>                 return rx_dtap(scu, a_conn_info, msg);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/13307">change 13307</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/13307"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-msc </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I3b89dd5a66ec83b03860b58b6b8eb58007f433a4 </div>
<div style="display:none"> Gerrit-Change-Number: 13307 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: dexter <pmaier@sysmocom.de> </div>