aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2020-05-11 21:41:56 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2020-05-22 13:18:15 +0200
commitcd3d6268a619b9533c26dfe068defeac3e00d094 (patch)
treee5e21d18023da3245069e0ef54cc314be743c6fc
parent30eb8ca6aaf265675b0e73e903a84646a9320699 (diff)
utils: do not crash when all bytes of EF.IMSI are 0xFF
In case try to decode the contents of an uninitalized EF.IMSI, the function dec_imsi() would crash because it truncates all 0xFF from the swapped version of the EF.IMSI contents and then accesses the first element of the buffer. This always works for EF.IMSI contents that contain valid IMSI data, but if all bytes are set to 0xFF, then no data is left in the buffer after truncating, so lets check if we even have bytes left before we move on with the decoding. Change-Id: I93874a1d7e0b87d39e4b06a5c504643cfabb451c
-rw-r--r--pySim/utils.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/pySim/utils.py b/pySim/utils.py
index b5203dc..2de6856 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -85,6 +85,8 @@ def dec_imsi(ef):
l = int(ef[0:2], 16) * 2 # Length of the IMSI string
l = l - 1 # Encoded length byte includes oe nibble
swapped = swap_nibbles(ef[2:]).rstrip('f')
+ if len(swapped) < 1:
+ return None
oe = (int(swapped[0])>>3) & 1 # Odd (1) / Even (0)
if not oe:
# if even, only half of last byte was used