fixeria has uploaded this change for review.

View Change

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 source pointer (and zero length), which is undefined behaviour:

vlr.c:1104:3: runtime error: null pointer passed as argument 2,
which is declared to never be null

Also, the length of the QoS profile was not checked against the size of
the destination buffer, so a QoS profile longer than 20 octets would
overflow it. Skip memcpy() for an empty QoS profile, and ignore QoS
profiles which do not fit.

Change-Id: If5adc05664fa3dce268105836001bce6d46448b8
Related: osmo-msc.git If4a5e3e7a0bcf2bcb5aba89c4f12468d51f5af8f
---
M src/libvlr/vlr.c
1 file changed, 9 insertions(+), 2 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/44/44244/1
diff --git a/src/libvlr/vlr.c b/src/libvlr/vlr.c
index a2012d9..a104f44 100644
--- a/src/libvlr/vlr.c
+++ b/src/libvlr/vlr.c
@@ -1101,8 +1101,15 @@
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);
- pdp_data->qos_subscribed_len = pdp_info->qos_enc_len;
+ if (pdp_info->qos_enc_len > sizeof(pdp_data->qos_subscribed)) {
+ LOGVSUBP(LOGL_ERROR, vsub, "PDP info (context id = %zu): QoS profile too long (%zu > %zu), "
+ "ignoring\n", ctx_id, pdp_info->qos_enc_len, sizeof(pdp_data->qos_subscribed));
+ pdp_data->qos_subscribed_len = 0;
+ } else {
+ 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;
+ }
}
}

To view, visit change 44244. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Change-Id: If5adc05664fa3dce268105836001bce6d46448b8
Gerrit-Change-Number: 44244
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de>