From 2a1123144b2f67f2406fe98f949af1ee34ed2594 Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Thu, 12 May 2016 09:36:04 +0300 Subject: [PATCH 1/3] modules/sdpops: remove duplicate body length arithmetic parse_sdp() pre-checks (parser/sdp/sdp.c) are identical --- modules/sdpops/sdpops_mod.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sdpops/sdpops_mod.c b/modules/sdpops/sdpops_mod.c index 5984332d6d9..dae05f9d115 100644 --- a/modules/sdpops/sdpops_mod.c +++ b/modules/sdpops/sdpops_mod.c @@ -403,7 +403,7 @@ int sdp_remove_line_by_prefix(sip_msg_t* msg, str* prefix) LM_ERR("failed to get the message body\n"); return -1; } - body.len = msg->len - (body.s - msg->buf); + if (body.len==0) { LM_DBG("message body has zero length\n"); return -1; From 85f00d65b4c30d61af134c0e72967d334638733d Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Thu, 12 May 2016 10:42:32 +0300 Subject: [PATCH 2/3] modules/sdpops: use parse_sdp() return value to bail out on empty body --- modules/sdpops/sdpops_mod.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/modules/sdpops/sdpops_mod.c b/modules/sdpops/sdpops_mod.c index dae05f9d115..6b800cdeb0d 100644 --- a/modules/sdpops/sdpops_mod.c +++ b/modules/sdpops/sdpops_mod.c @@ -386,16 +386,11 @@ int sdp_remove_line_by_prefix(sip_msg_t* msg, str* prefix) { str body = {NULL, 0}; - if(parse_sdp(msg) < 0) { + if(parse_sdp(msg) != 0) { LM_ERR("Unable to parse SDP\n"); return -1; } - if(msg->body == NULL) { - LM_DBG("No SDP body\n"); - return -1; - } - body.s = ((sdp_info_t*)msg->body)->raw_sdp.s; body.len = ((sdp_info_t*)msg->body)->raw_sdp.len; From 1fe1769d152a901c08ac0f5eb29dbe2ea8f26c6c Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Thu, 12 May 2016 10:58:21 +0300 Subject: [PATCH 3/3] test/unit: update unit 60 sdp_remove_line_by_prefix: test case for empty SIP body --- test/unit/60-message-sdp8.sip | 9 +++++++++ test/unit/60.cfg | 3 +++ test/unit/60.sh | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/unit/60-message-sdp8.sip diff --git a/test/unit/60-message-sdp8.sip b/test/unit/60-message-sdp8.sip new file mode 100644 index 00000000000..02581bb9f24 --- /dev/null +++ b/test/unit/60-message-sdp8.sip @@ -0,0 +1,9 @@ +MESSAGE sip:bob@example.invalid SIP/2.0 +From: sip:alice@example.invalid;tag=45dfdf49 +To: sip:bob@example.invalid +Call-ID: 1172299593a +CSeq: 1 MESSAGE +Content-Type: application/sdp +Max-Forwards: 2 +X-Info: sdpops remove_line_by_prefix() test8 - empty body + diff --git a/test/unit/60.cfg b/test/unit/60.cfg index 683875ad1cb..62c0a5b3e46 100644 --- a/test/unit/60.cfg +++ b/test/unit/60.cfg @@ -26,6 +26,9 @@ route { sl_send_reply(200,"OK"); exit; } + sl_send_reply(500,"Unknown test case"); + exit; + } else { $var(rc) = sdp_remove_line_by_prefix("a=X-cap"); if ( $var(rc) < 0 ) { diff --git a/test/unit/60.sh b/test/unit/60.sh index 0564b7da843..c4871362d03 100755 --- a/test/unit/60.sh +++ b/test/unit/60.sh @@ -38,7 +38,8 @@ if [ "${ret}" -ne 0 ] ; then fi # Borken SDP should give 500 response -sipsak -f 60-message-sdp0.sip -L -s sip:127.0.0.1 -v > ${TMPFILE} +FILE="60-message-sdp0.sip" +sipsak -f ${FILE} -L -s sip:127.0.0.1 -v > ${TMPFILE} ret=$? if [ "${ret}" -eq 1 ] ; then ret=0 @@ -66,9 +67,23 @@ for i in 1 2 3 4 5 6 7; do ret=1 echo "found ${PREFIXAFTER} lines that should be deleted (${FILE})" fi + else + echo "invalid sipsak return: ${ret}" fi done +# Empty body should get 500 response +FILE="60-message-sdp8.sip" +sipsak -f ${FILE} -L -s sip:127.0.0.1 -v > ${TMPFILE} +ret=$? +if [ "${ret}" -eq 1 ] ; then + ret=0 +else + echo "empty body not rejected" + ret=1 + exit ${ret} +fi + ${KILL} exit ${ret}