From 2cd1dda631713a188f285775b19667e252e3a681 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Sun, 26 May 2019 00:14:16 +0700 Subject: gsm48_decode_bcd_number2(): fix output truncation Thanks to the new unit test for BCD number encoding / decoding, it was discovered that gsm48_decode_bcd_number2() does not properly handle encoded LV if the output buffer size is equal to the original MSISDN length + 1 (\0-terminator): one digit is lost. For example, decoding of 15-digit long MSISDN to a buffer of size 16 (15 digits + 1 for \0) would give us only 14 digits. The problem was that 'output_len' was being decremented before checking the remaining buffer length and writing a digit to it. As a result, the maximum length was always one byte shorter. Change-Id: I61d49387fedbf7b238e21540a5eff22f6861e27a Fixes: OS#4025 --- tests/gsm0408/gsm0408_test.ok | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/gsm0408') diff --git a/tests/gsm0408/gsm0408_test.ok b/tests/gsm0408/gsm0408_test.ok index 2441b2b4..3938e870 100644 --- a/tests/gsm0408/gsm0408_test.ok +++ b/tests/gsm0408/gsm0408_test.ok @@ -167,14 +167,14 @@ BSD number encoding / decoding test - Actual: (rc=9) '0821436587092143f5' - Decoding HEX (buffer limit=16) '0821436587092143f5'... - Expected: (rc=0) '123456789012345' - - Actual: (rc=0) '12345678901234' + - Actual: (rc=0) '123456789012345' - Running test: to be truncated 20-digit MSISDN - Encoding ASCII (buffer limit=9) '12345678901234567890'... - Expected: (rc=-5) '' - Actual: (rc=-5) '' - Decoding HEX (buffer limit=16) '0a21436587092143658709'... - Expected: (rc=0) '123456789012345' - - Actual: (rc=0) '12345678901234' + - Actual: (rc=0) '123456789012345' - Running test: LV incorrect length - Decoding HEX (buffer limit=0) '05214365'... - Expected: (rc=-5) '(none)' -- cgit v1.2.3