Ethereal-dev: [Ethereal-dev] more mgcp fixes

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Ed Warnicke <hagbard@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 28 Dec 2000 00:59:28 -0500 (EST)
Please check in these other mgcp plugin fixes.

Ed

? mgcp-plugin-0.0.2.patch
Index: ChangeLog
===================================================================
RCS file: /cvsroot/ethereal/plugins/mgcp/ChangeLog,v
retrieving revision 1.1
diff -u -r1.1 ChangeLog
--- ChangeLog	2000/11/09 10:04:48	1.1
+++ ChangeLog	2000/12/28 05:56:17
@@ -0,0 +1,3 @@
+Overview of changes in Ethereal MGCP plugin 0.0.2:
+* Fixed misc problems with improperly dissecting some xgcp packets as 
+  short or malformed.  
Index: moduleinfo.h
===================================================================
RCS file: /cvsroot/ethereal/plugins/mgcp/moduleinfo.h,v
retrieving revision 1.1
diff -u -r1.1 moduleinfo.h
--- moduleinfo.h	2000/11/09 10:04:48	1.1
+++ moduleinfo.h	2000/12/28 05:56:17
@@ -13,5 +13,5 @@
 #endif
 
 /* Version number of package */
-#define VERSION "0.0.1"
+#define VERSION "0.0.2"
 
Index: packet-mgcp.c
===================================================================
RCS file: /cvsroot/ethereal/plugins/mgcp/packet-mgcp.c,v
retrieving revision 1.10
diff -u -r1.10 packet-mgcp.c
--- packet-mgcp.c	2000/12/25 09:37:35	1.10
+++ packet-mgcp.c	2000/12/28 05:56:18
@@ -2,7 +2,7 @@
  * Routines for mgcp packet disassembly
  * RFC 2705
  *
- * $Id: packet-mgcp.c,v 1.10 2000/12/25 09:37:35 guy Exp $
+ * $Id: packet-mgcp.c,v 1.9 2000/12/20 05:45:27 gram Exp $
  * 
  * Copyright (c) 2000 by Ed Warnicke <hagbard@xxxxxxxxxxxxxxxxxxx>
  *
@@ -434,32 +434,32 @@
 
   mgcp_module = prefs_register_module("mgcp", "MGCP", proto_reg_handoff_mgcp);
 
-  prefs_register_uint_preference(mgcp_module, "tcp.gateway_port", 
+  prefs_register_uint_preference(mgcp_module, "tcp.port", 
 				 "MGCP Gateway TCP Port",
-				 "Set the UDP port for gateway messages "
-				 "(if other than the default of 2427)",
+				 "Set the port for  gateway messages (if other"
+				 " than the default of 2427)",
 				 10, &global_mgcp_gateway_tcp_port);
 
-  prefs_register_uint_preference(mgcp_module, "udp.gateway_port", 
-				 "MGCP Gateway UDP Port",
-				 "Set the TCP port for gateway messages "
-				 "(if other than the default of 2427)",
+  prefs_register_uint_preference(mgcp_module, "udp.port", 
+				 "MGCP UDP Gateway Port",
+				 "Set the port for  gateway messages (if other"
+				 " than the default of 2427)",
 				 10, &global_mgcp_gateway_udp_port);
 
-  prefs_register_uint_preference(mgcp_module, "tcp.callagent_port", 
+  prefs_register_uint_preference(mgcp_module, "tcp.port", 
 				 "MGCP Callagent TCP Port",
-				 "Set the TCP port for callagent messages "
+				 "Set the port for  callagent messages" 
 				 "(if other than the default of 2727)",
 				 10, &global_mgcp_callagent_tcp_port);
 
-  prefs_register_uint_preference(mgcp_module, "udp.callagent_port", 
-				 "MGCP Callagent UDP Port",
-				 "Set the UDP port for callagent messages "
+  prefs_register_uint_preference(mgcp_module, "udp.port", 
+				 "MGCP UDP Gateway Port",
+				 "Set the port for  callagent messages "
 				 "(if other than the default of 2727)",
 				 10, &global_mgcp_callagent_udp_port);
 
 
-  prefs_register_bool_preference(mgcp_module, "display_raw_text", 
+  prefs_register_bool_preference(mgcp_module, "display raw text toggle", 
                                  "Display raw text for MGCP message", 
                                  "Specifies that the raw text of the "
                                  "MGCP message should be displayed "
@@ -467,7 +467,7 @@
 				 "dissection tree",
                                  &global_mgcp_raw_text);
 
-  prefs_register_bool_preference(mgcp_module, "display_dissect_tree", 
+  prefs_register_bool_preference(mgcp_module, "display dissect tree", 
                                  "Display tree dissection for MGCP message", 
                                  "Specifies that the dissection tree of the "
                                  "MGCP message should be displayed "
@@ -812,15 +812,18 @@
       my_proto_tree_add_string = proto_tree_add_string_hidden;
     }
 
-    tvb_current_offset = tvb_find_guint8(tvb,tvb_previous_offset,
-					     tvb_current_len, ' ');
-    if(tvb_current_offset == -1){
-      tvb_current_offset = tvb_len;
-    }
-    tvb_current_len = tvb_length_remaining(tvb,tvb_previous_offset);
-    tokenlen = tvb_current_offset - tvb_previous_offset;
+    do {
+      tvb_current_len = tvb_length_remaining(tvb,tvb_previous_offset);
+      tvb_current_offset = tvb_find_guint8(tvb, tvb_previous_offset,
+					   tvb_current_len, ' ');
+      if(tvb_current_offset == -1){
+	tvb_current_offset = tvb_len;
+	tokenlen = tvb_current_len;
+      }				  
+      else{
+	tokenlen = tvb_current_offset - tvb_previous_offset;
+      }
 
-    while( tvb_current_offset < tvb_len || tokennum <= 3){
       if(tokennum == 0){
 	if(is_mgcp_verb(tvb,tvb_previous_offset,tvb_current_len)){
 	  mgcp_type = MGCP_REQUEST;
@@ -849,38 +852,46 @@
       if(tokennum == 2){
 	if(mgcp_type == MGCP_REQUEST){
 	  my_proto_tree_add_string(tree,hf_mgcp_req_endpoint, tvb,
-				tvb_previous_offset, tokenlen,
-				tvb_format_text(tvb, tvb_previous_offset,
-						tokenlen));
+				   tvb_previous_offset, tokenlen,
+				   tvb_format_text(tvb, tvb_previous_offset,
+						   tokenlen));
 	}
 	else if(mgcp_type == MGCP_RESPONSE){
-	  tokenlen = tvb_find_line_end(tvb, tvb_previous_offset, 
-				       -1,&tvb_current_offset);
-	  my_proto_tree_add_string(tree,hf_mgcp_rsp_rspstring, tvb,
+	  if(tvb_current_offset < tvb_len){
+	    tokenlen = tvb_find_line_end(tvb, tvb_previous_offset, 
+					 -1,&tvb_current_offset);
+	  }
+	  else{
+	    tokenlen = tvb_current_len;
+	  }
+	  my_proto_tree_add_string(tree, hf_mgcp_rsp_rspstring, tvb,
 				   tvb_previous_offset, tokenlen,
-				   tvb_format_text(tvb,tvb_previous_offset,
+				   tvb_format_text(tvb, tvb_previous_offset,
 						   tokenlen));
-	  break;
-	}
+	  }
+	break;
       }
       if( (tokennum == 3 && mgcp_type == MGCP_REQUEST) ){
-	tokenlen = tvb_find_line_end(tvb, tvb_previous_offset, 
-				     -1,&tvb_current_offset);
+	if(tvb_current_offset < tvb_len ){
+	  tokenlen = tvb_find_line_end(tvb, tvb_previous_offset, 
+				       -1,&tvb_current_offset);
+	}
+	else{
+	  tokenlen = tvb_current_len;
+	}
 	my_proto_tree_add_string(tree,hf_mgcp_version, tvb,
 				 tvb_previous_offset, tokenlen,
 				 tvb_format_text(tvb,tvb_previous_offset,
 						 tokenlen));
 	break;
       }
-      tvb_previous_offset = tvb_skip_wsp(tvb, tvb_current_offset,
-					 tvb_current_len);
-      tvb_current_len = tvb_length_remaining(tvb,tvb_previous_offset);
-      tvb_current_offset = tvb_find_guint8(tvb,tvb_previous_offset,
-					   tvb_current_len, ' ');
-      tokenlen = tvb_current_offset - tvb_previous_offset;
+      if(tvb_current_offset < tvb_len){
+	tvb_previous_offset = tvb_skip_wsp(tvb, tvb_current_offset,
+					   tvb_current_len);
+      }
       tokennum++;
-    }
-  
+    } while( tvb_current_offset < tvb_len && tvb_previous_offset < tvb_len 
+	     && tokennum <= 3);
     switch (mgcp_type){
     case MGCP_RESPONSE:
       proto_tree_add_boolean_hidden(tree,hf_mgcp_rsp, NullTVB,0,0,1);
@@ -972,8 +983,13 @@
  */
 static gint tvb_skip_wsp(tvbuff_t* tvb, gint offset, gint maxlength){
   gint counter = offset;
-  gint end = offset + maxlength;
+  gint end = offset + maxlength,tvb_len;
   guint8 tempchar;
+  tvb_len = tvb_length(tvb);
+  end = offset + maxlength;
+  if(end >= tvb_len){
+    end = tvb_len;
+  }
   for(counter = offset; counter < end && 
 	((tempchar = tvb_get_guint8(tvb,counter)) == ' ' || 
 	tempchar == '\t');counter++);