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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">csn1: fix M_CHOICE: restirct maximum length of the choice list<br><br>The current implementation is not capable of handling more than<br>256 (UCHAR_MAX) selectors in the choice list. Let's document<br>this and add a guard check to the M_CHOICE handler.<br><br>Change-Id: I40c3c5b9be892804c6cd71cbb907af469ce5d769<br>---<br>M src/csn1.c<br>M src/csn1.h<br>2 files changed, 4 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/csn1.c b/src/csn1.c</span><br><span>index 3db1e13..3347a64 100644</span><br><span>--- a/src/csn1.c</span><br><span>+++ b/src/csn1.c</span><br><span>@@ -495,6 +495,8 @@</span><br><span>         /* Make sure that the list of choice items is not empty */</span><br><span>         if (!count)</span><br><span>           return ProcessError(readIndex, "csnStreamDecoder", CSN_ERROR_IN_SCRIPT, pDescr);</span><br><span style="color: hsl(120, 100%, 40%);">+        else if (count > 255) /* We can handle up to 256 (UCHAR_MAX) selectors */</span><br><span style="color: hsl(120, 100%, 40%);">+          return ProcessError(readIndex, "csnStreamDecoder", CSN_ERROR_IN_SCRIPT, pDescr);</span><br><span> </span><br><span>         while (count > 0)</span><br><span>         {</span><br><span>diff --git a/src/csn1.h b/src/csn1.h</span><br><span>index d178ada..7eef5c8 100644</span><br><span>--- a/src/csn1.h</span><br><span>+++ b/src/csn1.h</span><br><span>@@ -490,7 +490,8 @@</span><br><span>  * is the part of the message.  In the CSN_CHOICE case, this rule does not</span><br><span>  * apply. There is free but predefined mapping of the element of the union and</span><br><span>  * the value which addresses this element.</span><br><span style="color: hsl(0, 100%, 40%);">- * The value of the address is called a selector.</span><br><span style="color: hsl(120, 100%, 40%);">+ * The value of the address is called a selector. Up to 256 (UCHAR_MAX) unique</span><br><span style="color: hsl(120, 100%, 40%);">+ * selectors can be handled, longer choice list would cause CSN_ERROR_IN_SCRIPT.</span><br><span>  * After unpacking, this value is then converted to the sequential number of the</span><br><span>  * element in the union and stored in the UnionType variable.</span><br><span>  *      Par1: C structure name</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-pcu/+/18430">change 18430</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/+/18430"/><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: I40c3c5b9be892804c6cd71cbb907af469ce5d769 </div>
<div style="display:none"> Gerrit-Change-Number: 18430 </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>