From 0a8d9f05b8fc702e4b10e59a6e3788f1fb547117 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Fri, 16 Dec 2022 16:44:37 +0100 Subject: [PATCH] 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 --- pySim/cards.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pySim/cards.py b/pySim/cards.py index 55965d7e..4eff38cd 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -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)