summaryrefslogtreecommitdiffstats
path: root/src/codec
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2016-11-07 14:49:13 +0100
committerMax <msuraev@sysmocom.de>2016-11-07 15:19:47 +0100
commite9e5f8e4e9aa3fdce06d144381d9621552476387 (patch)
treef1a11ee01ca8c3c7c7a58102f88edc051fc20c6d /src/codec
parent8b25a3f5c38a9297f9213cb6e70b7599ba999fbe (diff)
Add null-pointer check to osmo_amr_rtp_dec()
Check that RTP payload we're about to decode is not NULL and return proper error code instead of segfaulting. Add corresponding test case. Change-Id: Ib6cda9900a41ed16bbfbde9df3de9d38e0a7469b
Diffstat (limited to 'src/codec')
-rw-r--r--src/codec/gsm690.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/codec/gsm690.c b/src/codec/gsm690.c
index 0f4bf8fe..c3cb9324 100644
--- a/src/codec/gsm690.c
+++ b/src/codec/gsm690.c
@@ -252,6 +252,9 @@ int osmo_amr_rtp_dec(const uint8_t *rtppayload, int payload_len, uint8_t *cmr,
int8_t *cmi, enum osmo_amr_type *ft,
enum osmo_amr_quality *bfi, int8_t *sti)
{
+ if (payload_len < 2 || !rtppayload)
+ return -EINVAL;
+
/* RFC 4867 ยง 4.4.2 ToC - compound payloads are not supported: F = 0 */
uint8_t type = (rtppayload[1] >> 3) & 0xf;
@@ -262,9 +265,6 @@ int osmo_amr_rtp_dec(const uint8_t *rtppayload, int payload_len, uint8_t *cmr,
if (payload_len - 2 < amr_len_by_ft[type])
return -ENOTSUP;
- if (payload_len < 2)
- return -EINVAL;
-
if (ft)
*ft = type;