Change in osmo-mgw[master]: mgcp_conn_get(): match conn Id ('I:') despite leading zeros

2018-09-07 Thread Neels Hofmeyr
Neels 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, >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 = "23AB";
const char *conn_id_request[] = {
+   "23AB",
+   "0023AB",
"23AB",
+   "0023AB",
+   "23ab",
+   "0023ab",
"23ab",
+   "0023ab",
};

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 '23AB'
+needle='0023AB' found '23AB'
 needle='23AB' found '23AB'
+needle='0023AB' found '23AB'
+needle='23ab' found '23AB'
+needle='0023ab' found '23AB'
 needle='23ab' found '23AB'
+needle='0023ab' found '23AB'
 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 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Reviewer: Neels Hofmeyr 


Change in osmo-mgw[master]: mgcp_conn_get(): match conn Id ('I:') despite leading zeros

2018-09-07 Thread Harald Welte
Harald Welte has posted comments on this change. ( 
https://gerrit.osmocom.org/10678 )

Change subject: mgcp_conn_get(): match conn Id ('I:') despite leading zeros
..


Patch Set 5: Code-Review+2


--
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: comment
Gerrit-Change-Id: If55a64a2da47b6eff035711c08e4114d70dbec91
Gerrit-Change-Number: 10678
Gerrit-PatchSet: 5
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Comment-Date: Fri, 07 Sep 2018 09:10:19 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in osmo-mgw[master]: mgcp_conn_get(): match conn Id ('I:') despite leading zeros

2018-09-06 Thread Neels Hofmeyr
Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/10678

to look at the new patch set (#5).

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(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/78/10678/5
--
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: newpatchset
Gerrit-Change-Id: If55a64a2da47b6eff035711c08e4114d70dbec91
Gerrit-Change-Number: 10678
Gerrit-PatchSet: 5
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)


Change in osmo-mgw[master]: mgcp_conn_get(): match conn Id ('I:') despite leading zeros

2018-09-06 Thread Neels Hofmeyr
Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/10678

to look at the new patch set (#4).

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
Depends: Ib0ee1206b9f31d7ba25c31f8008119ac55440797 (libosmocore)
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/4
--
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: newpatchset
Gerrit-Change-Id: If55a64a2da47b6eff035711c08e4114d70dbec91
Gerrit-Change-Number: 10678
Gerrit-PatchSet: 4
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)


Change in osmo-mgw[master]: mgcp_conn_get(): match conn Id ('I:') despite leading zeros

2018-09-04 Thread Harald Welte
Harald Welte has posted comments on this change. ( 
https://gerrit.osmocom.org/10678 )

Change subject: mgcp_conn_get(): match conn Id ('I:') despite leading zeros
..


Patch Set 3: Code-Review+2


--
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: comment
Gerrit-Change-Id: If55a64a2da47b6eff035711c08e4114d70dbec91
Gerrit-Change-Number: 10678
Gerrit-PatchSet: 3
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Comment-Date: Tue, 04 Sep 2018 17:56:48 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in osmo-mgw[master]: mgcp_conn_get(): match conn Id ('I:') despite leading zeros

2018-09-03 Thread Neels Hofmeyr
Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/10678

to look at the new patch set (#3).

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/3
--
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: newpatchset
Gerrit-Change-Id: If55a64a2da47b6eff035711c08e4114d70dbec91
Gerrit-Change-Number: 10678
Gerrit-PatchSet: 3
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)


Change in osmo-mgw[master]: mgcp_conn_get(): match conn Id ('I:') despite leading zeros

2018-08-29 Thread Harald Welte
Harald Welte has posted comments on this change. ( 
https://gerrit.osmocom.org/10678 )

Change subject: mgcp_conn_get(): match conn Id ('I:') despite leading zeros
..


Patch Set 1: Code-Review+2


--
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: comment
Gerrit-Change-Id: If55a64a2da47b6eff035711c08e4114d70dbec91
Gerrit-Change-Number: 10678
Gerrit-PatchSet: 1
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Comment-Date: Wed, 29 Aug 2018 07:17:23 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in osmo-mgw[master]: mgcp_conn_get(): match conn Id ('I:') despite leading zeros

2018-08-28 Thread Neels Hofmeyr
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, >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 = "23AB";
const char *conn_id_request[] = {
+   "23AB",
+   "0023AB",
"23AB",
+   "0023AB",
+   "23ab",
+   "0023ab",
"23ab",
+   "0023ab",
};

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 '23AB'
+needle='0023AB' found '23AB'
 needle='23AB' found '23AB'
+needle='0023AB' found '23AB'
+needle='23ab' found '23AB'
+needle='0023ab' found '23AB'
 needle='23ab' found '23AB'
+needle='0023ab' found '23AB'
 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