[sofia-sip] Fix sdp_session_cmp(), add test. Scan-build: Fix multiple dereferences of null pointer.
This commit is contained in:
parent
c714401935
commit
fe65102738
|
@ -1 +1 @@
|
|||
Fri Jan 17 15:37:19 UTC 2020
|
||||
Wed Feb 12 22:23:00 UTC 2020
|
||||
|
|
|
@ -1189,8 +1189,8 @@ int sdp_session_cmp(sdp_session_t const *a, sdp_session_t const *b)
|
|||
|
||||
for (ab = a->sdp_bandwidths, bb = b->sdp_bandwidths;
|
||||
ab || bb;
|
||||
ab = ab->b_next, bb = bb->b_next)
|
||||
if ((rv = sdp_bandwidth_cmp(a->sdp_bandwidths, b->sdp_bandwidths)))
|
||||
ab = (ab ? ab->b_next : NULL), bb = (bb ? bb->b_next : NULL))
|
||||
if ((rv = sdp_bandwidth_cmp(ab, bb)))
|
||||
return rv;
|
||||
|
||||
if ((rv = sdp_time_cmp(a->sdp_time, b->sdp_time)))
|
||||
|
@ -1199,14 +1199,14 @@ int sdp_session_cmp(sdp_session_t const *a, sdp_session_t const *b)
|
|||
return rv;
|
||||
|
||||
for (aa = a->sdp_attributes, ba = b->sdp_attributes;
|
||||
aa || bb;
|
||||
aa = aa->a_next, ba = ba->a_next)
|
||||
aa || ba;
|
||||
aa = (aa ? aa->a_next : NULL), ba = (ba ? ba->a_next : NULL))
|
||||
if ((rv = sdp_attribute_cmp(aa, ba)))
|
||||
return rv;
|
||||
|
||||
for (am = a->sdp_media, bm = b->sdp_media;
|
||||
am || bm;
|
||||
am = am->m_next, bm = bm->m_next)
|
||||
am = (am ? am->m_next : NULL), bm = (bm ? bm->m_next : NULL))
|
||||
if ((rv = sdp_media_cmp(am, bm)))
|
||||
return rv;
|
||||
|
||||
|
@ -1268,6 +1268,9 @@ int sdp_bandwidth_cmp(sdp_bandwidth_t const *a, sdp_bandwidth_t const *b)
|
|||
if ((a != NULL) != (b != NULL))
|
||||
return (a != NULL) < (b != NULL) ? -1 : 1;
|
||||
|
||||
if (!a || !b)
|
||||
return -1;
|
||||
|
||||
if (a->b_modifier != b->b_modifier)
|
||||
return a->b_modifier < b->b_modifier ? -1 : 1;
|
||||
if (a->b_modifier == sdp_bw_x &&
|
||||
|
@ -1310,6 +1313,9 @@ int sdp_repeat_cmp(sdp_repeat_t const *a, sdp_repeat_t const *b)
|
|||
if ((a != NULL) != (b != NULL))
|
||||
return (a != NULL) < (b != NULL) ? -1 : 1;
|
||||
|
||||
if (!a || !b)
|
||||
return -1;
|
||||
|
||||
if (a->r_interval != b->r_interval)
|
||||
return a->r_interval < b->r_interval ? -1 : 1;
|
||||
if (a->r_duration != b->r_duration)
|
||||
|
@ -1397,6 +1403,9 @@ int sdp_rtpmap_cmp(sdp_rtpmap_t const *a, sdp_rtpmap_t const *b)
|
|||
if ((a != NULL) != (b != NULL))
|
||||
return (a != NULL) < (b != NULL) ? -1 : 1;
|
||||
|
||||
if (!a || !b)
|
||||
return -1;
|
||||
|
||||
if (a->rm_pt != b->rm_pt)
|
||||
return a->rm_pt < b->rm_pt ? -1 : 1;
|
||||
|
||||
|
@ -1456,6 +1465,9 @@ int sdp_media_cmp(sdp_media_t const *a, sdp_media_t const *b)
|
|||
if ((rv = (a != NULL) - (b != NULL)))
|
||||
return rv;
|
||||
|
||||
if (!a || !b)
|
||||
return -1;
|
||||
|
||||
if (a->m_type != b->m_type)
|
||||
return a->m_type < b->m_type ? -1 : 1;
|
||||
if (a->m_type == sdp_media_x)
|
||||
|
@ -1482,7 +1494,7 @@ int sdp_media_cmp(sdp_media_t const *a, sdp_media_t const *b)
|
|||
|
||||
for (arm = a->m_rtpmaps, brm = b->m_rtpmaps;
|
||||
arm || brm;
|
||||
arm = arm->rm_next, brm = brm->rm_next)
|
||||
arm = (arm ? arm->rm_next : NULL), brm = (brm ? brm->rm_next : NULL))
|
||||
if ((rv = sdp_rtpmap_cmp(arm, brm)))
|
||||
return rv;
|
||||
|
||||
|
@ -1494,13 +1506,13 @@ int sdp_media_cmp(sdp_media_t const *a, sdp_media_t const *b)
|
|||
|
||||
for (ac = a->m_connections, bc = b->m_connections;
|
||||
ac || bc;
|
||||
ac = ac->c_next, bc = bc->c_next)
|
||||
ac = (ac ? ac->c_next : NULL), bc = (bc ? bc->c_next : NULL))
|
||||
if ((rv = sdp_connection_cmp(ac, bc)))
|
||||
return rv;
|
||||
|
||||
for (ab = a->m_bandwidths, bb = b->m_bandwidths;
|
||||
ab || bb;
|
||||
ab = ab->b_next, bb = bb->b_next)
|
||||
ab = (ab ? ab->b_next : NULL), bb = (bb ? bb->b_next : NULL))
|
||||
if ((rv = sdp_bandwidth_cmp(ab, bb)))
|
||||
return rv;
|
||||
|
||||
|
@ -1509,7 +1521,7 @@ int sdp_media_cmp(sdp_media_t const *a, sdp_media_t const *b)
|
|||
|
||||
for (aa = a->m_attributes, ba = b->m_attributes;
|
||||
aa || ba;
|
||||
aa = aa->a_next, ba = ba->a_next)
|
||||
aa = (aa ? aa->a_next : NULL), ba = (ba ? ba->a_next : NULL))
|
||||
if ((rv = sdp_attribute_cmp(aa, ba)))
|
||||
return rv;
|
||||
|
||||
|
|
|
@ -225,6 +225,83 @@ static int test_session(void)
|
|||
END();
|
||||
}
|
||||
|
||||
|
||||
static char const s0_cmp_msg[] =
|
||||
"v=0\n"
|
||||
"s=/sdp_torture\n"
|
||||
"o=sdp_torture 0 0 IN IP4 0.0.0.0\n"
|
||||
"b=AS:64\n"
|
||||
"b=CRASH:32\n"
|
||||
"m=audio 0 RTP/AVP 96 97 98 10 99 8 0\n"
|
||||
"a=rtpmap:96 X-AMR-WB/16000\n"
|
||||
"a=rtpmap:97 X-AMR/8000\n"
|
||||
"a=rtpmap:98 GSM-EFR/8000\n"
|
||||
"a=rtpmap:10 L16/16000\n"
|
||||
"a=rtpmap:99 G723/8000\n"
|
||||
"a=rtpmap:8 PCMA/8000\n"
|
||||
"a=rtpmap:0 PCMU/8000\n"
|
||||
"m=video 0 *\n"
|
||||
"m=* 0 RTP/AVP *\n"
|
||||
;
|
||||
|
||||
static char const s1_cmp_msg[] =
|
||||
"v=0\n"
|
||||
"s=/sdp_torture\n"
|
||||
"o=sdp_torture 0 0 IN IP4 0.0.0.0\n"
|
||||
"b=AS:64\n"
|
||||
"m=audio 0 RTP/AVP 96 97 98 10 99 8 0\n"
|
||||
"a=rtpmap:96 X-AMR-WB/16000\n"
|
||||
"a=rtpmap:97 X-AMR/8000\n"
|
||||
"a=rtpmap:98 GSM-EFR/8000\n"
|
||||
"a=rtpmap:10 L16/16000\n"
|
||||
"a=rtpmap:99 G723/8000\n"
|
||||
"a=rtpmap:8 PCMA/8000\n"
|
||||
"a=rtpmap:0 PCMU/8000\n"
|
||||
"m=video 0 *\n"
|
||||
"m=* 0 RTP/AVP *\n"
|
||||
;
|
||||
|
||||
static int test_sdp_session_cmp(void)
|
||||
{
|
||||
su_home_t *home = su_home_create(), *home2 = su_home_create();
|
||||
sdp_session_t *sdp_src, *sdp_target;
|
||||
sdp_session_t const *sdp = NULL;
|
||||
sdp_parser_t *parser, *parser2;
|
||||
|
||||
BEGIN();
|
||||
|
||||
su_home_check(home);
|
||||
TEST_1(home);
|
||||
|
||||
su_home_check(home2);
|
||||
TEST_1(home2);
|
||||
|
||||
TEST_1((parser = sdp_parse(home, s0_cmp_msg, sizeof(s0_cmp_msg), sdp_f_config)));
|
||||
TEST_1((sdp_src = sdp_session(parser)));
|
||||
|
||||
TEST_1((parser2 = sdp_parse(home2, s1_cmp_msg, sizeof(s1_cmp_msg), sdp_f_config)));
|
||||
TEST_1((sdp_target = sdp_session(parser2)));
|
||||
|
||||
/* Check comparing */
|
||||
TEST(sdp_session_cmp(sdp_src, sdp_target), 1);
|
||||
|
||||
/* frees all data created by the parser including 'sdp_src' */
|
||||
sdp_parser_free(parser);
|
||||
|
||||
/* destroy the first home instance */
|
||||
su_home_check(home);
|
||||
su_home_unref(home);
|
||||
|
||||
/* frees all data created by the parser including 'sdp_target' */
|
||||
sdp_parser_free(parser2);
|
||||
|
||||
/* destroy the second home object */
|
||||
su_home_check(home2);
|
||||
su_home_unref(home2);
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
static char const s1_msg[] =
|
||||
"v=0\r\n"
|
||||
"o=- 2435697 2435697 IN IP4 172.21.137.44\r\n"
|
||||
|
@ -925,6 +1002,7 @@ int main(int argc, char *argv[])
|
|||
null = fopen("/dev/null", "ab");
|
||||
|
||||
retval |= test_error(); fflush(stdout);
|
||||
retval |= test_sdp_session_cmp(); fflush(stdout);
|
||||
retval |= test_session(); fflush(stdout);
|
||||
retval |= test_session2(); fflush(stdout);
|
||||
retval |= test_pint(); fflush(stdout);
|
||||
|
|
Loading…
Reference in New Issue