cards: check length of mnc more restrictively
Since we now ensure that mnc always has a valid length lets make the
check in cards.py more strict.
Related: OS#5830
Change-Id: Iee8f25416e0cc3be96dff025affb1dc11d919fcd
diff --git a/pySim/cards.py b/pySim/cards.py
index 55965d7..4eff38c 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -205,11 +205,12 @@
# perform updates
if mnc and abstract_data['extensions']:
+ # Note: Since we derive the length of the MNC by the string length
+ # of the mnc parameter, the caller must ensure that mnc has the
+ # correct length and is padded with zeros (if necessary).
mnclen = len(str(mnc))
- if mnclen == 1:
- mnclen = 2
- if mnclen > 3:
- raise RuntimeError('invalid length of mnc "{}"'.format(mnc))
+ if mnclen > 3 or mnclen < 2:
+ raise RuntimeError('invalid length of mnc "{}", expecting 2 or 3 digits'.format(mnc))
abstract_data['extensions']['mnc_len'] = mnclen
if opmode:
opmode_num = int(opmode, 16)