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.orgNeels Hofmeyr has submitted this change and it was merged. ( 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.
Now, mgcp_conn_get() would match a valid id with *any* amount of leading zeros,
even if that far surpasses the permitted conn id length. Valid lengths of
incoming conn ids should be and is checked elsewhere.
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(-)
Approvals:
Harald Welte: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c
index 0918b8b..820c63a 100644
--- a/src/libosmo-mgcp/mgcp_conn.c
+++ b/src/libosmo-mgcp/mgcp_conn.c
@@ -190,17 +190,25 @@
{
struct mgcp_conn *conn;
const char *id_upper;
+ const char *conn_id;
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. */
id_upper = osmo_str_toupper(id);
llist_for_each_entry(conn, &endp->conns, entry) {
- if (strcmp(conn->id, id_upper) == 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 99ddd71..b9f7253 100644
--- a/tests/mgcp/mgcp_test.c
+++ b/tests/mgcp/mgcp_test.c
@@ -1759,8 +1759,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 f50f487..28e9aad 100644
--- a/tests/mgcp/mgcp_test.ok
+++ b/tests/mgcp/mgcp_test.ok
@@ -1171,6 +1171,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: merged
Gerrit-Change-Id: If55a64a2da47b6eff035711c08e4114d70dbec91
Gerrit-Change-Number: 10678
Gerrit-PatchSet: 5
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180907/a9836f31/attachment.htm>