This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Neels Hofmeyr gerrit-no-reply at lists.osmocom.orgReview at https://gerrit.osmocom.org/4156 gsm: make osmo_imsi_str_valid() NULL-safe No callers that would pass NULL exist, but let's check against NULL from the start. Fixup for recent change I1e94f5b0717b947d2a7a7d36bacdf04a75cb3522. Change-Id: I111fbf29228929f2cd6ffa06bcb1f69da223224e --- M src/gsm/gsm23003.c M tests/gsm23003/gsm23003_test.c M tests/gsm23003/gsm23003_test.ok 3 files changed, 6 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/56/4156/1 diff --git a/src/gsm/gsm23003.c b/src/gsm/gsm23003.c index 004e20f..732d3d3 100644 --- a/src/gsm/gsm23003.c +++ b/src/gsm/gsm23003.c @@ -33,13 +33,13 @@ /* Use unsigned char * to avoid a compiler warning of * "error: array subscript has type 'char' [-Werror=char-subscripts]" */ const unsigned char *pos = (const unsigned char *)str; - for (len = 0; *pos && len < max_digits; len++, pos++) + for (len = 0; pos && *pos && len < max_digits; len++, pos++) if (!isdigit(*pos)) return false; if (len < min_digits) return false; /* With not too many digits, we should have reached *str == nul */ - if (*pos) + if (pos && *pos) return false; return true; } diff --git a/tests/gsm23003/gsm23003_test.c b/tests/gsm23003/gsm23003_test.c index 682f162..a408b73 100644 --- a/tests/gsm23003/gsm23003_test.c +++ b/tests/gsm23003/gsm23003_test.c @@ -50,6 +50,7 @@ { "1234567\n123456", false }, { "123456\t123456", false }, { "123456\r123456", false }, + { NULL, false }, }; bool test_valid_imsi() @@ -92,6 +93,7 @@ { "1234567\n123456", false }, { "123456\t123456", false }, { "123456\r123456", false }, + { NULL, false }, }; bool test_valid_msisdn() diff --git a/tests/gsm23003/gsm23003_test.ok b/tests/gsm23003/gsm23003_test.ok index 777451a..7d7ffd1 100644 --- a/tests/gsm23003/gsm23003_test.ok +++ b/tests/gsm23003/gsm23003_test.ok @@ -19,6 +19,7 @@ 123456' 17: expect=false result=false imsi='123456 123456' 18: expect=false result=false imsi='123456 123456' +19: expect=false result=false imsi='(null)' ----- test_valid_msisdn 0: expect=false result=false msisdn='' 1: expect=false result=false msisdn=' ' @@ -40,3 +41,4 @@ 123456' 17: expect=false result=false msisdn='123456 123456' 18: expect=false result=false msisdn='123456 123456' +19: expect=false result=false msisdn='(null)' -- To view, visit https://gerrit.osmocom.org/4156 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I111fbf29228929f2cd6ffa06bcb1f69da223224e Gerrit-PatchSet: 1 Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>