laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/pysim/+/41581?usp=email )

Change subject: ts_31_102: EF SUCI_Calc_Info: fix decoding empty files
......................................................................

ts_31_102: EF SUCI_Calc_Info: fix decoding empty files

When trying to use `edit_binary_decoded` with an empty file, pysim
runs into a len(None) exception, because hpkl.to_dict()['hnet_pubkey_list'] 
returns
None.

Can reproduced with a CCC Camp 2023 usim and editing the file.
a000ff..ff (len = 200)

Co-authored-by: Harald Welte <[email protected]>
Change-Id: Ib8e322e65dd768bfd49e7a5620a2163f12a74ec7
---
M pySim/ts_31_102.py
1 file changed, 9 insertions(+), 1 deletion(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved




diff --git a/pySim/ts_31_102.py b/pySim/ts_31_102.py
index 2f7b945..b354b32 100644
--- a/pySim/ts_31_102.py
+++ b/pySim/ts_31_102.py
@@ -285,6 +285,14 @@
                                 {"hnet_pubkey_identifier": 11, "hnet_pubkey":
                                  
h2b("d1bc365f4997d17ce4374e72181431cbfeba9e1b98d7618f79d48561b144672a")}]} ),
     ]
+    _test_decode = [
+        ( 'A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
+          {"prot_scheme_id_list": [],
+           "hnet_pubkey_list": []} ),
+        ( 'A000A100FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
+          {"prot_scheme_id_list": [],
+           "hnet_pubkey_list": []} ),
+    ]
     # 3GPP TS 31.102 Section 4.4.11.8
     class ProtSchemeIdList(BER_TLV_IE, tag=0xa0):
         # FIXME: 3GPP TS 24.501 Protection Scheme Identifier
@@ -389,7 +397,7 @@
         # remaining data holds Home Network Public Key Data Object
         hpkl = EF_SUCI_Calc_Info.HnetPubkeyList()
         hpkl.from_tlv(in_bytes[pos:])
-        hnet_pubkey_list = 
self._compact_pubkey_list(hpkl.to_dict()['hnet_pubkey_list'])
+        hnet_pubkey_list = 
self._compact_pubkey_list(hpkl.to_dict()['hnet_pubkey_list'] or [])

         return {
             'prot_scheme_id_list': prot_scheme_id_list,

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/41581?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ib8e322e65dd768bfd49e7a5620a2163f12a74ec7
Gerrit-Change-Number: 41581
Gerrit-PatchSet: 3
Gerrit-Owner: lynxis lazus <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>

Reply via email to