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
This commit is contained in:
Philipp Maier 2019-01-08 10:40:18 +01:00 committed by dexter
parent 64b51eb68b
commit d6ef6f1b91
1 changed files with 6 additions and 1 deletions

View File

@ -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