fixeria has uploaded this change for review.
cbsp: cbsp_decode_cell_list(): validate the list length
Change-Id: I2d8fe20744715044ea4a54abb7cd0212246587fa
Related: OS#7098
---
M src/gsm/cbsp.c
M tests/smscb/cbsp_test.c
M tests/smscb/cbsp_test.ok
3 files changed, 9 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/78/44178/1
diff --git a/src/gsm/cbsp.c b/src/gsm/cbsp.c
index 233cbf3..bdb7369 100644
--- a/src/gsm/cbsp.c
+++ b/src/gsm/cbsp.c
@@ -528,6 +528,12 @@
return -EINVAL;
}
+ /* remaining len must be a multiple of cell_id_size */
+ if ((len - 1) == 0 || (len - 1) % cell_id_size) {
+ osmo_cbsp_errstr = "cell list: malformed/empty";
+ return -EINVAL;
+ }
+
while (cur < buf + len) {
struct osmo_cbsp_cell_ent *ent = talloc_zero(ctx, struct osmo_cbsp_cell_ent);
unsigned int len_remain = len - (cur - buf);
diff --git a/tests/smscb/cbsp_test.c b/tests/smscb/cbsp_test.c
index f59dbc1..7ed5121 100644
--- a/tests/smscb/cbsp_test.c
+++ b/tests/smscb/cbsp_test.c
@@ -102,7 +102,7 @@
.hex_pdu = "1000000404000205ff",
},
{
- /* XXX: CELL_IDENT_LAC with missing LAC => expected failure (passes) */
+ /* CELL_IDENT_LAC with missing LAC => failure */
.name = "CBSP RESET: Cell List (LAC, missing)",
.hex_pdu = "1000000404000105",
},
diff --git a/tests/smscb/cbsp_test.ok b/tests/smscb/cbsp_test.ok
index bbc1ff0..df09370 100644
--- a/tests/smscb/cbsp_test.ok
+++ b/tests/smscb/cbsp_test.ok
@@ -13,10 +13,10 @@
TC[3] osmo_cbsp_decode() result: pass
TC[4] 'CBSP RESET: Cell List (LAC, short)'
TC[4] PDU: 1000000404000205ff
-TC[4] osmo_cbsp_decode() result: cell list: error decoding cell_id_union
+TC[4] osmo_cbsp_decode() result: cell list: malformed/empty
TC[5] 'CBSP RESET: Cell List (LAC, missing)'
TC[5] PDU: 1000000404000105
-TC[5] osmo_cbsp_decode() result: pass
+TC[5] osmo_cbsp_decode() result: cell list: malformed/empty
TC[6] 'CBSP RESET: Cell List (malformed TLV)'
TC[6] PDU: 100000040400ff05
TC[6] osmo_cbsp_decode() result: error
To view, visit change 44178. To unsubscribe, or for help writing mail filters, visit settings.