diff options
author | Max <msuraev@sysmocom.de> | 2016-11-07 14:49:13 +0100 |
---|---|---|
committer | Max <msuraev@sysmocom.de> | 2016-11-07 15:19:47 +0100 |
commit | e9e5f8e4e9aa3fdce06d144381d9621552476387 (patch) | |
tree | f1a11ee01ca8c3c7c7a58102f88edc051fc20c6d /tests/codec | |
parent | 8b25a3f5c38a9297f9213cb6e70b7599ba999fbe (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 'tests/codec')
-rw-r--r-- | tests/codec/codec_test.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/tests/codec/codec_test.c b/tests/codec/codec_test.c index 5b934b13..f944f38b 100644 --- a/tests/codec/codec_test.c +++ b/tests/codec/codec_test.c @@ -38,12 +38,17 @@ static const char * cmpr(int a, int b) static void test_sid_dec(const uint8_t *t, size_t len) { - uint8_t cmr, tmp[SID_LEN]; + uint8_t cmr, tmp[SID_LEN], *t2 = NULL; enum osmo_amr_type ft; enum osmo_amr_quality bfi; int8_t sti, cmi; - memcpy(tmp, t, SID_LEN); - int rc = osmo_amr_rtp_dec(tmp, len, &cmr, &cmi, &ft, &bfi, &sti); + if (t) { + memcpy(tmp, t, SID_LEN); + t2 = tmp; + } + int rc = osmo_amr_rtp_dec(t2, len, &cmr, &cmi, &ft, &bfi, &sti); + if (rc < 0) + return; printf("[%d] decode RTP %s%s: FT %s, CMR %s, CMI is %d, SID type %s\t", rc, osmo_hexdump(tmp, len), cmpr(bfi, AMR_GOOD), get_value_string(osmo_amr_type_names, ft), @@ -94,6 +99,7 @@ int main(int argc, char **argv) printf("AMR RTP payload decoder test:\n"); test_sid_dec(sid_first, 7); test_sid_dec(sid_update, 7); + test_sid_dec(NULL, 7); test_amr_rt(0, AMR_NO_DATA, AMR_BAD); test_amr_rt(0, AMR_NO_DATA, AMR_GOOD); test_amr_rt(AMR_12_2, AMR_12_2, AMR_BAD); |