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
This commit is contained in:
Philipp Maier 2022-12-16 16:44:37 +01:00
parent 32c0434540
commit 0a8d9f05b8
1 changed files with 5 additions and 4 deletions

View File

@ -205,11 +205,12 @@ class SimCard:
# 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)