[M] Change in osmo-msc[master]: libvlr: fix memcpy() of PDP QoS profile from InsertSubscriberData
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-msc/+/44239?usp=email ) Change subject: libvlr: fix memcpy() of PDP QoS profile from InsertSubscriberData ...................................................................... libvlr: fix memcpy() of PDP QoS profile from InsertSubscriberData If the HLR sends PDP info without a QoS profile, memcpy() is called with a NULL src pointer and zero length, which is undefined behaviour: vlr.c:1121:3: runtime error: null pointer passed as argument 2, which is declared to never be null Skip memcpy() for an empty QoS profile. Add a unit test sending PDP info without QoS, with a too long QoS and with a valid QoS profile. Change-Id: If4a5e3e7a0bcf2bcb5aba89c4f12468d51f5af8f Related: osmo-sgsn.git If5adc05664fa3dce268105836001bce6d46448b8 --- M src/libvlr/vlr.c M tests/msc_vlr/msc_vlr_test_no_authen.c M tests/msc_vlr/msc_vlr_test_no_authen.err 3 files changed, 58 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/39/44239/1 diff --git a/src/libvlr/vlr.c b/src/libvlr/vlr.c index 64e235d..26d4252 100644 --- a/src/libvlr/vlr.c +++ b/src/libvlr/vlr.c @@ -1118,7 +1118,8 @@ memcpy(&pdp_data->pdp_address[1], &pdp_info->pdp_address[1], sizeof(pdp_data->pdp_address[1])); osmo_apn_to_str(pdp_data->apn_str, pdp_info->apn_enc, pdp_info->apn_enc_len); - memcpy(pdp_data->qos_subscribed, pdp_info->qos_enc, pdp_info->qos_enc_len); + if (pdp_info->qos_enc_len > 0) + memcpy(pdp_data->qos_subscribed, pdp_info->qos_enc, pdp_info->qos_enc_len); pdp_data->qos_subscribed_len = pdp_info->qos_enc_len; } } diff --git a/tests/msc_vlr/msc_vlr_test_no_authen.c b/tests/msc_vlr/msc_vlr_test_no_authen.c index 3d17a52..8be7fda 100644 --- a/tests/msc_vlr/msc_vlr_test_no_authen.c +++ b/tests/msc_vlr/msc_vlr_test_no_authen.c @@ -1006,6 +1006,38 @@ comment_end(); } +static void test_no_authen_isd_pdp_info(void) +{ + struct vlr_subscr *vsub; + const char *imsi = "901700000004620"; + + comment_start(); + + btw("Create a subscriber in the VLR, no LU is needed to test InsertSubscriberData"); + vsub = vlr_subscr_find_or_create_by_imsi(net->vlr, imsi, __func__, NULL); + OSMO_ASSERT(vsub); + + btw("HLR sends _INSERT_DATA_REQUEST with PDP info: without QoS, with too long QoS, with valid QoS"); + gsup_rx("10010809710000004026f00804036470f1" + /* PDP info: context id 1, APN "internet", no QoS profile */ + "050e" "100101" "120908696e7465726e6574" + /* PDP info: context id 2, APN "internet", QoS profile of 21 octets (too long) */ + "0525" "100102" "120908696e7465726e6574" + "1315" "000102030405060708090a0b0c0d0e0f1011121314" + /* PDP info: context id 3, APN "internet", QoS profile of 3 octets */ + "0513" "100103" "120908696e7465726e6574" "13030e9396" + HLR_TO_VLR, + "12010809710000004026f0" VLR_TO_HLR); + + btw("PDP info with too long QoS profile is ignored, the other two are stored"); + VERBOSE_ASSERT(llist_count(&vsub->ps.pdp_list), == 2, "%d"); + + vlr_subscr_put(vsub, __func__); + EXPECT_CONN_COUNT(0); + clear_vlr(); + comment_end(); +} + msc_vlr_test_func_t msc_vlr_tests[] = { test_no_authen, test_no_authen_tmsi, @@ -1017,5 +1049,6 @@ test_no_authen_imeisv_tmsi_imei, test_no_authen_subscr_expire, test_no_authen_tmsi_nri_no_fit, + test_no_authen_isd_pdp_info, NULL }; diff --git a/tests/msc_vlr/msc_vlr_test_no_authen.err b/tests/msc_vlr/msc_vlr_test_no_authen.err index c0e1216..3dd2ee5 100644 --- a/tests/msc_vlr/msc_vlr_test_no_authen.err +++ b/tests/msc_vlr/msc_vlr_test_no_authen.err @@ -3149,3 +3149,26 @@ llist_count(&msub_list) == 0 ===== test_no_authen_tmsi_nri_no_fit: SUCCESS +===== test_no_authen_isd_pdp_info +- Create a subscriber in the VLR, no LU is needed to test InsertSubscriberData +DVLR VLR subscr unknown + test_no_authen_isd_pdp_info: now used by 1 (test_no_authen_isd_pdp_info) +DVLR set IMSI on subscriber; IMSI=901700000004620 id=901700000004620 +DVLR New subscr, IMSI: 901700000004620 +- HLR sends _INSERT_DATA_REQUEST with PDP info: without QoS, with too long QoS, with valid QoS +<-- GSUP rx OSMO_GSUP_MSGT_INSERT_DATA_REQUEST: 10010809710000004026f00804036470f1050e100101120908696e7465726e65740525100102120908696e7465726e65741315000102030405060708090a0b0c0d0e0f10111213140513100103120908696e7465726e657413030e93960a0101 +DVLR VLR subscr IMSI-901700000004620 + vlr_gsup_rx: now used by 2 (test_no_authen_isd_pdp_info,vlr_gsup_rx) +DVLR IMSI:901700000004620 has MSISDN:46071 +DVLR SUBSCR(IMSI-901700000004620:MSISDN-46071) Will set PDP info, context id = 1, APN = 08 69 6e 74 65 72 6e 65 74 +DVLR SUBSCR(IMSI-901700000004620:MSISDN-46071) QoS info too long (21) +DVLR SUBSCR(IMSI-901700000004620:MSISDN-46071) Will set PDP info, context id = 3, APN = 08 69 6e 74 65 72 6e 65 74 +DMSC msub(unknown) VLR: update for IMSI=901700000004620 (MSISDN=46071) (NO CONN!) +GSUP --> HLR: OSMO_GSUP_MSGT_INSERT_DATA_RESULT: 12010809710000004026f00a0101 +DVLR VLR subscr IMSI-901700000004620:MSISDN-46071 - vlr_gsup_rx: now used by 1 (test_no_authen_isd_pdp_info) +<-- GSUP rx OSMO_GSUP_MSGT_INSERT_DATA_REQUEST: vlr_gsupc_read_cb() returns 0 +- PDP info with too long QoS profile is ignored, the other two are stored + llist_count(&vsub->ps.pdp_list) == 2 +DVLR VLR subscr IMSI-901700000004620:MSISDN-46071 - test_no_authen_isd_pdp_info: now used by 0 (-) +DVLR SUBSCR(IMSI-901700000004620:MSISDN-46071) freeing VLR subscr (max total use count was 2) + llist_count(&msub_list) == 0 +===== test_no_authen_isd_pdp_info: SUCCESS + -- To view, visit https://gerrit.osmocom.org/c/osmo-msc/+/44239?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmo-msc Gerrit-Branch: master Gerrit-Change-Id: If4a5e3e7a0bcf2bcb5aba89c4f12468d51f5af8f Gerrit-Change-Number: 44239 Gerrit-PatchSet: 1 Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de>
participants (1)
-
fixeria