<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/osmo-pcu/+/17120">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">csn1: fix csnStreamDecoder(): catch unknown CSN_CHOICE values<br><br>After the recent changes [1], it was noticed that one of the unit<br>tests fails. In particular, a decode-encode cycle of Packet<br>Polling Request produces a different vector:<br><br>  vector1 = 49 13 e0 08 50 88 40 13 a8 04 8b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b<br>  vector2 = 49 13 01 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b<br>  vector1 == vector2 : FALSE<br><br>As it turns out, the original (input) vector itself is malformed<br>because it contails no valid identity, and thus violates the<br>specs. The CSN.1 decoder from Pycrate [2] throws an exception<br>while trying to decode it. I believe we should do the same.<br><br>Let's stop decoding the bit stream and return an error in case<br>if neither of a given list of the choice items matched.<br><br>[1] Ia0f8cc224a4c38e80699f834fd83d4c0d99322ea<br>[2] https://github.com/P1sec/pycrate<br><br>Change-Id: I420144773ed5e80372534e0f18db5e74cdb2999d<br>Fixes: OS#4392<br>---<br>M src/csn1.cpp<br>M tests/rlcmac/RLCMACTest.ok<br>2 files changed, 10 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/csn1.cpp b/src/csn1.cpp</span><br><span>index 01e3a43..5928d69 100644</span><br><span>--- a/src/csn1.cpp</span><br><span>+++ b/src/csn1.cpp</span><br><span>@@ -495,6 +495,10 @@</span><br><span>         guint8 i     = 0;</span><br><span>         CSN_ChoiceElement_t* pChoice = (CSN_ChoiceElement_t*) pDescr->descr.ptr;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+        /* Make sure that the list of choice items is not empty */</span><br><span style="color: hsl(120, 100%, 40%);">+        if (!count)</span><br><span style="color: hsl(120, 100%, 40%);">+          return ProcessError(readIndex, "csnStreamDecoder", CSN_ERROR_IN_SCRIPT, pDescr);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>         while (count > 0)</span><br><span>         {</span><br><span>           guint8 no_of_bits = pChoice->bits;</span><br><span>@@ -537,6 +541,10 @@</span><br><span>           i++;</span><br><span>         }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+        /* Neither of the choice items matched => unknown value */</span><br><span style="color: hsl(120, 100%, 40%);">+        if (!count)</span><br><span style="color: hsl(120, 100%, 40%);">+          return ProcessError(readIndex, "csnStreamDecoder", CSN_ERROR_STREAM_NOT_SUPPORTED, pDescr);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>         pDescr++;</span><br><span>         break;</span><br><span>       }</span><br><span>diff --git a/tests/rlcmac/RLCMACTest.ok b/tests/rlcmac/RLCMACTest.ok</span><br><span>index 24ea4b7..2d27ca4 100644</span><br><span>--- a/tests/rlcmac/RLCMACTest.ok</span><br><span>+++ b/tests/rlcmac/RLCMACTest.ok</span><br><span>@@ -58,11 +58,11 @@</span><br><span> vector1 == vector2 : TRUE</span><br><span> vector1 = 4913e00850884013a8048b2b2b2b2b2b2b2b2b2b2b2b2b</span><br><span> =========Start DECODE===========</span><br><span style="color: hsl(0, 100%, 40%);">-+++++++++Finish DECODE (0)++++++++++</span><br><span>++++++++++Finish DECODE (-8)++++++++++</span><br><span> =========Start ENCODE=============</span><br><span> +++++++++Finish ENCODE (0)+++++++++++</span><br><span> vector1 = 49 13 e0 08 50 88 40 13 a8 04 8b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b </span><br><span style="color: hsl(0, 100%, 40%);">-vector2 = 49 13 01 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b </span><br><span style="color: hsl(120, 100%, 40%);">+vector2 = 49 13 00 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b </span><br><span> vector1 == vector2 : FALSE</span><br><span> vector1 = 412430007fffffffffffffffefd19c7ba12b2b2b2b2b2b</span><br><span> =========Start DECODE===========</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-pcu/+/17120">change 17120</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/osmo-pcu/+/17120"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-pcu </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I420144773ed5e80372534e0f18db5e74cdb2999d </div>
<div style="display:none"> Gerrit-Change-Number: 17120 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: fixeria <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: fixeria <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>