Neels Hofmeyr has uploaded this change for review. ( https://gerrit.osmocom.org/10678
Change subject: mgcp_conn_get(): match conn Id ('I:') despite leading zeros ...................................................................... mgcp_conn_get(): match conn Id ('I:') despite leading zeros The Connection Identifier is defined as a hex string, so clients may send the ID back with or without leading zeros. Ignore all leading zeros when comparing. A specific SCCPlite MSC is observed to DLCX with Connection Identifier with leading zeros removed, which would mismatch pefore this patch. Extend test_conn_id_matching() in mgcp_test.c to include leading zero tests. Related: OS#3509 Change-Id: If55a64a2da47b6eff035711c08e4114d70dbec91 --- M src/libosmo-mgcp/mgcp_conn.c M tests/mgcp/mgcp_test.c M tests/mgcp/mgcp_test.ok 3 files changed, 21 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/78/10678/1 diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c index 89c55ed..9027411 100644 --- a/src/libosmo-mgcp/mgcp_conn.c +++ b/src/libosmo-mgcp/mgcp_conn.c @@ -189,11 +189,16 @@ { struct mgcp_conn *conn; char id_upper[MGCP_CONN_ID_LENGTH]; + const char *conn_id; int i; if (!id || !*id) return NULL; + /* Ignore leading zeros in needle */ + while (*id == '0') + id++; + /* Use uppercase to compare identifiers, to avoid mismatches: RFC3435 2.1.3.2 "Names of * Connections" defines the id as a hex string, so clients may return lower case hex even though * we sent upper case hex in the CRCX response. */ @@ -202,7 +207,10 @@ id_upper[i] = toupper(id_upper[i]); llist_for_each_entry(conn, &endp->conns, entry) { - if (strncmp(conn->id, id_upper, sizeof(conn->id)) == 0) + /* Ignore leading zeros in haystack */ + for (conn_id=conn->id; *conn_id == '0'; conn_id++); + + if (strcmp(conn_id, id_upper) == 0) return conn; } diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c index bb1cd98..ea66069 100644 --- a/tests/mgcp/mgcp_test.c +++ b/tests/mgcp/mgcp_test.c @@ -1752,8 +1752,14 @@ int i; const char *conn_id_generated = "000023AB"; const char *conn_id_request[] = { + "23AB", + "0023AB", "000023AB", + "00000023AB", + "23ab", + "0023ab", "000023ab", + "00000023ab", }; printf("\nTesting %s\n", __func__); diff --git a/tests/mgcp/mgcp_test.ok b/tests/mgcp/mgcp_test.ok index 34dcd14..9a6d5c2 100644 --- a/tests/mgcp/mgcp_test.ok +++ b/tests/mgcp/mgcp_test.ok @@ -1158,6 +1158,12 @@ '10,a :PCMU' -> '(null)' Testing test_conn_id_matching +needle='23AB' found '000023AB' +needle='0023AB' found '000023AB' needle='000023AB' found '000023AB' +needle='00000023AB' found '000023AB' +needle='23ab' found '000023AB' +needle='0023ab' found '000023AB' needle='000023ab' found '000023AB' +needle='00000023ab' found '000023AB' Done -- To view, visit https://gerrit.osmocom.org/10678 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-MessageType: newchange Gerrit-Change-Id: If55a64a2da47b6eff035711c08e4114d70dbec91 Gerrit-Change-Number: 10678 Gerrit-PatchSet: 1 Gerrit-Owner: Neels Hofmeyr <nhofm...@sysmocom.de>