From d6ef6f1b9163be659693bb546276ab2f655f9cb9 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Tue, 8 Jan 2019 10:40:18 +0100 Subject: gsm29118: fix coverity issues The function msgb_sgsap_name_put() assignes the return code of osmo_apn_from_str() directly to len. Len is an uint8_t and the return code an int. If osmo_apn_from_str() returns -1. Len would become 0xFF causing a buffer overrun with msgb_tlv_put. Lets use the proper type to catch the return code and check it before using it as length. Change-Id: Ic0bc5114eee47bdcf2300a6e4b0df473d3d1903a Fixes: CID#190405 Fixes: CID#190401 Related: OS#3615 --- src/gsm/gsm29118.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gsm/gsm29118.c b/src/gsm/gsm29118.c index ca210fbf..56e74738 100644 --- a/src/gsm/gsm29118.c +++ b/src/gsm/gsm29118.c @@ -196,9 +196,14 @@ static int msgb_sgsap_name_put(struct msgb *msg, enum sgsap_iei iei, const char { uint8_t buf[APN_MAXLEN]; uint8_t len; + int rc; + /* encoding is like DNS names, which is like APN fields */ memset(buf, 0, sizeof(buf)); - len = osmo_apn_from_str(buf, sizeof(buf), name); + rc = osmo_apn_from_str(buf, sizeof(buf), name); + if (rc < 0) + return -1; + len = (uint8_t)rc; /* Note: While the VLR-Name (see 3GPP TS 29.118, chapter 9.4.22) has * a flexible length, the MME-Name has a fixed size of 55 octets. (see -- cgit v1.2.3