pespin submitted this change.
sgsn_libgtp: encode IMEISV via a local LV buffer
gsm48_encode_bcd_number() was called on pdp->imeisv.v with max_len 8,
which only worked because it compares max_len against the L octet. A
16-digit IMEISV needs 9 bytes (L plus 8 octets). Encode into a local
9-byte LV buffer, check the return code, and copy the value part.
Related: OS#7126
Change-Id: Ied06aa05ee6850ec0df34a51cdce6df12e0b594c
---
M src/sgsn/sgsn_libgtp.c
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/sgsn/sgsn_libgtp.c b/src/sgsn/sgsn_libgtp.c
index b4c24a0..4573427 100644
--- a/src/sgsn/sgsn_libgtp.c
+++ b/src/sgsn/sgsn_libgtp.c
@@ -300,11 +300,18 @@
/* optional include the IMEI(SV) */
if (mmctx->imei[0] != '\0') {
- memset(&pdp->imeisv.v[0], 0, 8);
- pdp->imeisv_given = 1;
- gsm48_encode_bcd_number(&pdp->imeisv.v[0], 8, 0, mmctx->imei);
- pdp->imeisv.l = 8;
- memmove(&pdp->imeisv.v[0], &pdp->imeisv.v[1], 8);
+ /* the L octet plus 8 octets of IMEI(SV) digits */
+ uint8_t bcd_lv[9];
+
+ rc = gsm48_encode_bcd_number(bcd_lv, sizeof(bcd_lv), 0, mmctx->imei);
+ if (rc < 0) {
+ LOGPDPCTXP(LOGL_ERROR, pctx, "Cannot encode IMEI(SV) '%s'\n", mmctx->imei);
+ } else {
+ pdp->imeisv_given = 1;
+ pdp->imeisv.l = bcd_lv[0];
+ OSMO_ASSERT(pdp->imeisv.l + 1 <= sizeof(bcd_lv));
+ memcpy(&pdp->imeisv.v[0], &bcd_lv[1], pdp->imeisv.l);
+ }
}
/* change pdp state to 'requested' */
To view, visit change 44150. To unsubscribe, or for help writing mail filters, visit settings.