From 8368e7d5d59140fc77b890493a47a08cd644e2f8 Mon Sep 17 00:00:00 2001 From: Neels Janosch Hofmeyr Date: Thu, 1 Dec 2022 03:05:58 +0100 Subject: fix coding of Network Instance IE Network instance names should be coded like in DNS, where each label is preceded by a length byte. Related: SYS#6192 Change-Id: I9d67464ef0f92b0512cfd6e48d203f8828a82a19 --- src/libosmo-pfcp/Makefile.am | 2 ++ src/libosmo-pfcp/pfcp_ies_custom.c | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/libosmo-pfcp/Makefile.am b/src/libosmo-pfcp/Makefile.am index d202c6a..6ca88b8 100644 --- a/src/libosmo-pfcp/Makefile.am +++ b/src/libosmo-pfcp/Makefile.am @@ -9,12 +9,14 @@ AM_CPPFLAGS = \ AM_CFLAGS = \ -Wall \ $(LIBOSMOCORE_CFLAGS) \ + $(LIBOSMOGSM_CFLAGS) \ $(LIBOSMOVTY_CFLAGS) \ $(COVERAGE_CFLAGS) \ $(NULL) AM_LDFLAGS = \ $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOGSM_LIBS) \ $(LIBOSMOVTY_LIBS) \ $(COVERAGE_LDFLAGS) \ $(NULL) diff --git a/src/libosmo-pfcp/pfcp_ies_custom.c b/src/libosmo-pfcp/pfcp_ies_custom.c index 1891902..736f39d 100644 --- a/src/libosmo-pfcp/pfcp_ies_custom.c +++ b/src/libosmo-pfcp/pfcp_ies_custom.c @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -81,6 +82,13 @@ tlv->len - ((POS) - tlv->val)); \ } while (0) +#define ENSURE_RANGE(NAME, VAL, MINVAL, MAXVAL) \ + do { \ + if ((VAL) < (MINVAL) || (VAL) > (MAXVAL)) \ + RETURN_ERROR(-ERANGE, "%s == %d, should be in range %d .. %d", NAME, \ + (int)(VAL), (int)(MINVAL), (int)(MAXVAL)); \ + } while (0) + void osmo_pfcp_ie_f_seid_set(struct osmo_pfcp_ie_f_seid *f_seid, uint64_t seid, const struct osmo_sockaddr *remote_addr) { *f_seid = (struct osmo_pfcp_ie_f_seid) { @@ -698,16 +706,21 @@ int osmo_pfcp_enc_to_str_apply_action(char *buf, size_t buflen, const void *enco int osmo_pfcp_dec_network_inst(void *decoded_struct, void *decode_to, const struct osmo_gtlv_load *tlv) { struct osmo_pfcp_ie_network_inst *network_inst = decode_to; - osmo_strlcpy(network_inst->str, (const char *)tlv->val, OSMO_MIN(sizeof(network_inst->str), tlv->len+1)); + ENSURE_RANGE("Network Instance value length", tlv->len, 1, sizeof(network_inst->str)); + if (osmo_apn_to_str(network_inst->str, tlv->val, tlv->len) == NULL) + RETURN_ERROR(-EINVAL, "osmo_apn_to_str() failed"); return 0; } int osmo_pfcp_enc_network_inst(struct osmo_gtlv_put *tlv, const void *decoded_struct, const void *encode_from) { const struct osmo_pfcp_ie_network_inst *network_inst = encode_from; - unsigned int l = strlen(network_inst->str); - if (l) - memcpy(msgb_put(tlv->dst, l), network_inst->str, l); + int rc; + + rc = osmo_apn_from_str(tlv->dst->tail, msgb_tailroom(tlv->dst), network_inst->str); + if (rc <= 0) + RETURN_ERROR(-EINVAL, "osmo_apn_from_str(\"%s\") failed", network_inst->str); + msgb_put(tlv->dst, rc); return 0; } -- cgit v1.2.3