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

 (

2 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted 
one.
 )Change subject: sms: don't mutate digits in AddressField.to_bytes()
......................................................................

sms: don't mutate digits in AddressField.to_bytes()

to_bytes() appended the BCD filler nibble, so the next call saw one
digit more and derived a wrong length. This affects any code that encodes
an address twice, even for printing/logging.

Man, I really miss my beloved c++ const function decoration...

Fix: keep the filler in a local.
Change-Id: I81691c5a1fc5072d6d20c52d22da1eb2e180d04a
---
M pySim/sms.py
1 file changed, 3 insertions(+), 3 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  dexter: Looks good to me, approved
  Jenkins Builder: Verified




diff --git a/pySim/sms.py b/pySim/sms.py
index 75a9bde..55afbb7 100644
--- a/pySim/sms.py
+++ b/pySim/sms.py
@@ -246,8 +246,8 @@
     def to_bytes(self) -> bytes:
         """Encode the AddressField into the binary representation as used in 
T-PDU."""
         num_digits = len(self.digits)
-        if num_digits % 2:
-            self.digits += 'f'
+        # don't store the filler nibble or get_bytes() encodes it as digit and 
ends up too large
+        digits = self.digits + 'f' if num_digits % 2 else self.digits
         d = {
             'addr_len': num_digits,
             'type_of_addr': {
@@ -255,7 +255,7 @@
                 'type_of_number': self.ton,
                 'numbering_plan_id': self.npi,
                 },
-            'digits': self.digits,
+            'digits': digits,
             }
         return self._construct.build(d)


--
To view, visit https://gerrit.osmocom.org/c/pysim/+/43556?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: I81691c5a1fc5072d6d20c52d22da1eb2e180d04a
Gerrit-Change-Number: 43556
Gerrit-PatchSet: 3
Gerrit-Owner: Hoernchen <[email protected]>
Gerrit-Reviewer: Hoernchen <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>

Reply via email to