Prechádzať zdrojové kódy

Merge pull request #615 from mslehto/sdpops-remove_by_prefix-bodychk

modules/sdpops: remove_line_by_prefix pre-check cleanup + new test
Daniel-Constantin Mierla 9 rokov pred
rodič
commit
ace46b48f1

+ 2 - 7
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;
 
@@ -403,7 +398,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;

+ 9 - 0
test/unit/60-message-sdp8.sip

@@ -0,0 +1,9 @@
+MESSAGE sip:[email protected] SIP/2.0
+From: sip:[email protected];tag=45dfdf49
+To: sip:[email protected]
+Call-ID: 1172299593a
+CSeq: 1 MESSAGE
+Content-Type: application/sdp
+Max-Forwards: 2
+X-Info: sdpops remove_line_by_prefix() test8 - empty body
+

+ 3 - 0
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 ) {

+ 16 - 1
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}