r2703 - in trunk/libmsip/source: . messages

erik at minisip.org erik at minisip.org
Thu Aug 10 15:11:39 CEST 2006


Author: erik
Date: 2006-08-10 15:11:38 +0200 (Thu, 10 Aug 2006)
New Revision: 2703

Modified:
   trunk/libmsip/source/SipLayerTransport.cxx
   trunk/libmsip/source/SipStack.cxx
   trunk/libmsip/source/messages/SipResponse.cxx
Log:

 * Bug fix: We did an "massert" on data received when parsing SIP messages.
 	That made the application exit with a stack trace. Ok when
	debugging, but not for users. Now we discard such bad packets.



Modified: trunk/libmsip/source/SipLayerTransport.cxx
===================================================================
--- trunk/libmsip/source/SipLayerTransport.cxx	2006-08-10 12:09:30 UTC (rev 2702)
+++ trunk/libmsip/source/SipLayerTransport.cxx	2006-08-10 13:11:38 UTC (rev 2703)
@@ -882,6 +882,7 @@
 #ifdef DEBUG_OUTPUT
 				mdbg << "Invalid data on UDP socket, discarded" << end;
 #endif
+				cerr<< "Invalid data on UDP socket, discarded" << endl;
 				continue;
 			}
 			

Modified: trunk/libmsip/source/SipStack.cxx
===================================================================
--- trunk/libmsip/source/SipStack.cxx	2006-08-10 12:09:30 UTC (rev 2702)
+++ trunk/libmsip/source/SipStack.cxx	2006-08-10 13:11:38 UTC (rev 2703)
@@ -70,18 +70,13 @@
 
 SipStack::SipStack( MRef<SipCommonConfig *> stackConfig,
 		MRef<certificate_chain *> cert_chain,
-		MRef<ca_db *> cert_db//,
-		//MRef<TimeoutProvider<string, MRef<StateMachine<SipSMCommand,string>*> > *> tp
+		MRef<ca_db *> cert_db
 		)
 {
 	timers = new SipTimers;
 	this->config = stackConfig;
 
-//	if (tp){
-//		timeoutProvider = tp;
-//	}else{
-		timeoutProvider = new TimeoutProvider<string, MRef<StateMachine<SipSMCommand,string>*> >;
-//	}
+	timeoutProvider = new TimeoutProvider<string, MRef<StateMachine<SipSMCommand,string>*> >;
 
 	SipHeader::headerFactories.addFactory("Accept", sipHeaderAcceptFactory);
 	SipHeader::headerFactories.addFactory("Accept-Contact", sipHeaderAcceptContactFactory);

Modified: trunk/libmsip/source/messages/SipResponse.cxx
===================================================================
--- trunk/libmsip/source/messages/SipResponse.cxx	2006-08-10 12:09:30 UTC (rev 2702)
+++ trunk/libmsip/source/messages/SipResponse.cxx	2006-08-10 13:11:38 UTC (rev 2703)
@@ -85,29 +85,43 @@
 //TODO: This constructor needs rewriting (re-use from sipmessage)
 SipResponse::SipResponse(string &resp): SipMessage(-1, resp)
 {
+	int len = resp.size();
 
-	if(resp.size() < 11){
-#ifdef DEBUG_OUTPUT
-		cerr << "SipResponse::SipResponse: message too short - throwing exception"<< endl;
-#endif
-		throw SipExceptionInvalidMessage("SipResponse too short");
+	int i =0;
+
+	//If stream transport we should allow whitespace before the start
+	//of the message
+	while (i<len &&(resp[i]==' ' || resp[i]=='\r' || resp[i]=='\n' || resp[i]=='\t')){
+		i++;
 	}
 		//strlen(SIP/2.0)==7
-	int afterws=7;
-	while (resp[afterws]!='\0' && (resp[afterws]==' ' || resp[afterws]=='\t'))
+	if (!( i+7<=len && resp.substr(i,7)=="SIP/2.0" ) ){
+		throw SipExceptionInvalidMessage("SipResponse header error");
+	}
+	i+=7;
+
+	int afterws=i;
+	while ( afterws<len && resp[afterws]!='\0' && (resp[afterws]==' ' || resp[afterws]=='\t'))
 		afterws++;
-	massert(resp[afterws+0]>='0' && resp[afterws+0]<='9');
-	massert(resp[afterws+1]>='0' && resp[afterws+1]<='9');
-	massert(resp[afterws+2]>='0' && resp[afterws+2]<='9');
 	
+	if (afterws+3 >=len){
+		throw SipExceptionInvalidMessage("SipResponse header error");
+	}
+	
+	if (! (resp[afterws+0]>='0' && resp[afterws+0]<='9' &&
+				resp[afterws+1]>='0' && resp[afterws+1]<='9' &&
+				resp[afterws+2]>='0' && resp[afterws+2]<='9' ) ){
+		throw SipExceptionInvalidMessage("SipResponse without status code");
+	}
+	
 	status_code = (resp[afterws+0]-'0')*100 + (resp[afterws+1]-'0')*10 + resp[afterws+2]-'0';
 
 	status_desc="";
-	uint32_t i;
-	for (i=12; resp[i]!='\r' && resp[i]!='\n'; i++){
-		if(resp.size() == i){
+	i=afterws+3;	//go past response code
+	for ( ; resp[i]!='\r' && resp[i]!='\n'; i++){
+		if(len == i){
 #ifdef DEBUG_OUTPUT
-		cerr << "SipResponse::SipResponse: message did not end correctly - throwing exception"<< endl;
+		mdbg << "SipResponse::SipResponse: message did not end correctly - throwing exception"<< endl;
 #endif
 
 			throw SipExceptionInvalidMessage("SipResponse malformed - could not find end of response description");



More information about the Minisip-devel mailing list