<p>dexter has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/18208">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">utils: do not crash when all bytes of EF.IMSI are 0xFF<br><br>In case try to decode the contents of an uninitalized EF.IMSI, the<br>function dec_imsi() would crash because it truncates all 0xFF from the<br>swapped version of the EF.IMSI contents and then accesses the first<br>element of the buffer. This always worls for EF.IMSI contents that<br>contain valid IMSI data, but if all bytes are set to 0xFF, then no data<br>is left in the buffer after truncating, so lets check if we even have<br>bytes left before we move on with the decoding.<br><br>Change-Id: I93874a1d7e0b87d39e4b06a5c504643cfabb451c<br>---<br>M pySim/utils.py<br>1 file changed, 2 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/08/18208/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim/utils.py b/pySim/utils.py</span><br><span>index aab5d02..e5b0a74 100644</span><br><span>--- a/pySim/utils.py</span><br><span>+++ b/pySim/utils.py</span><br><span>@@ -81,6 +81,8 @@</span><br><span>  l = int(ef[0:2], 16) * 2                # Length of the IMSI string</span><br><span>  l = l - 1                                               # Encoded length byte includes oe nibble</span><br><span>     swapped = swap_nibbles(ef[2:]).rstrip('f')</span><br><span style="color: hsl(120, 100%, 40%);">+    if len(swapped) < 1:</span><br><span style="color: hsl(120, 100%, 40%);">+               return None</span><br><span>  oe = (int(swapped[0])>>3) & 1 # Odd (1) / Even (0)</span><br><span>         if not oe:</span><br><span>           # if even, only half of last byte was used</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/pysim/+/18208">change 18208</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/pysim/+/18208"/><meta itemprop="name" content="View Change"/></div></div>

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