Ethereal-dev: Re: [ethereal-dev] Patch for file.c

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

From: Ben Fowler <wapdev@xxxxxxxxxxxx>
Date: Fri, 12 May 2000 13:46:23 +0100

The enclosed patches changes do the following:

1) Add a number of assertion statements to packet.c.
2) Add a symbol BASE_MAX (to use in assertion statements,
3) Include stdio.h in tvbuff.c (to support fprintf( ) )
4) Change in white space. Where do you like spaces and parentheses?
I put 1 space after each opening parenthesis and before each closing
parenthesis.

Apologies if I have inadvertently included patches which have
already been rejected.

Is it best to put related patches, grouped in separate files, or
are you happy to have them in one.

Ben.

Index: packet.c
===================================================================
RCS file: /cvsroot/ethereal/packet.c,v
retrieving revision 1.81
diff -u -r1.81 packet.c
--- packet.c	2000/05/11 22:04:18	1.81
+++ packet.c	2000/05/12 10:16:51
@@ -845,6 +849,9 @@
   struct atalk_ddp_addr ddp_addr;
   struct sna_fid_type_4_addr sna_fid_type_4_addr;
 
+  g_assert( addr != NULL );
+
   switch (addr->type) {
 
   case AT_ETHER:
@@ -1343,9 +1350,11 @@
 	dissector_table_t sub_dissectors = find_dissector_table( name);
 
 /* sanity check */
-	g_assert( sub_dissectors);
+	g_assert( sub_dissectors );
 
 /* do the table insertion */
     	g_hash_table_insert( sub_dissectors, GUINT_TO_POINTER( pattern),
Index: proto.c
===================================================================
RCS file: /cvsroot/ethereal/proto.c,v
retrieving revision 1.64
diff -u -r1.64 proto.c
--- proto.c	2000/05/11 08:15:59	1.64
+++ proto.c	2000/05/12 10:16:59
@@ -317,15 +320,20 @@
 		return(NULL);
 
 	va_start(ap, length);
+	g_assert( length >= 0 );  /* ... zero length permitted e.g. call from packet.c */
+	g_assert(hfindex >= 0 && hfindex < gpa_hfinfo->len);
 	/* ap won't be used since format is NULL */
 	pi = proto_tree_add_pi(tree, hfindex, tvb, start, length,
 			NULL, TRUE, &new_fi, ap);
@@ -339,12 +347,14 @@
 		return(NULL);
 
 	va_start(ap, length);
+	g_assert( length > 0 );
+	g_assert(hfindex >= 0 && hfindex < gpa_hfinfo->len);
 	/* ap won't be used since format is NULL */
 	pi = proto_tree_add_pi(tree, hfindex, tvb, start, length,
 			NULL, FALSE, &new_fi, ap);
@@ -358,9 +368,12 @@
 
 	hfinfo = fi->hfinfo;
 
+	g_assert( length >= 0 );
 	/* from the stdarg man page on Solaris 2.6:
 	NOTES
 	     It is up to the calling routine to specify  in  some  manner
@@ -455,6 +482,7 @@
 	if (!tree)
 		return (NULL);
 
+	g_assert(hfindex >= 0 && hfindex < gpa_hfinfo->len);
 	hfinfo = proto_registrar_get_nth(hfindex);
 	g_assert(hfinfo->type == FT_NONE);
 
@@ -474,12 +502,13 @@
 	if (!tree)
 		return (NULL);
 
+	g_assert(hfindex >= 0 && hfindex < gpa_hfinfo->len);
 	hfinfo = proto_registrar_get_nth(hfindex);
 	g_assert(hfinfo->type == FT_BYTES);
 
@@ -511,12 +540,13 @@
 	if (!tree)
 		return (NULL);
 
+	g_assert(hfindex >= 0 && hfindex < gpa_hfinfo->len);
 	hfinfo = proto_registrar_get_nth(hfindex);
 	g_assert(hfinfo->type == FT_ABSOLUTE_TIME ||
 				hfinfo->type == FT_RELATIVE_TIME);
@@ -544,12 +574,13 @@
 	if (!tree)
 		return (NULL);
 
+	g_assert(hfindex >= 0 && hfindex < gpa_hfinfo->len);
 	hfinfo = proto_registrar_get_nth(hfindex);
 	g_assert(hfinfo->type == FT_IPXNET);
 
@@ -576,12 +607,13 @@
 	if (!tree)
 		return (NULL);
 
+	g_assert(hfindex >= 0 && hfindex < gpa_hfinfo->len);
 	hfinfo = proto_registrar_get_nth(hfindex);
 	g_assert(hfinfo->type == FT_IPv4);
 
@@ -609,12 +641,13 @@
 	if (!tree)
 		return (NULL);
 
+	g_assert(hfindex >= 0 && hfindex < gpa_hfinfo->len);
 	hfinfo = proto_registrar_get_nth(hfindex);
 	g_assert(hfinfo->type == FT_IPv6);
 
@@ -641,12 +674,13 @@
 	if (!tree)
 		return (NULL);
 
+	g_assert(hfindex >= 0 && hfindex < gpa_hfinfo->len);
 	hfinfo = proto_registrar_get_nth(hfindex);
 	g_assert(hfinfo->type == FT_STRING);
 
@@ -674,12 +708,13 @@
 	if (!tree)
 		return (NULL);
 
+	g_assert(hfindex >= 0 && hfindex < gpa_hfinfo->len);
 	hfinfo = proto_registrar_get_nth(hfindex);
 	g_assert(hfinfo->type == FT_ETHER);
 
@@ -706,12 +741,13 @@
 	if (!tree)
 		return (NULL);
 
+	g_assert(hfindex >= 0 && hfindex < gpa_hfinfo->len);
 	hfinfo = proto_registrar_get_nth(hfindex);
 	g_assert(hfinfo->type == FT_BOOLEAN);
 
@@ -738,12 +802,13 @@
 	if (!tree)
 		return (NULL);
 
+	g_assert(hfindex >= 0 && hfindex < gpa_hfinfo->len);
 	hfinfo = proto_registrar_get_nth(hfindex);
 	g_assert(hfinfo->type == FT_DOUBLE);
 
@@ -770,18 +835,20 @@
 	if (!tree)
 		return (NULL);
 
+	g_assert(hfindex >= 0 && hfindex < gpa_hfinfo->len);
 	hfinfo = proto_registrar_get_nth(hfindex);
 	switch(hfinfo->type) {
 		case FT_UINT8:
@@ -1004,31 +1078,42 @@
 
 	for (i = 0; i < num_records; i++, ptr++) {
 		field_id = proto_register_field_init(&ptr->hfinfo, parent);
+		g_assert( ptr->p_id != NULL );
 		*ptr->p_id = field_id;
 	}
 }
@@ -1098,6 +1188,8 @@
 		case FT_UINT32:
 			if (hfinfo->bitmask) {
 				if (hfinfo->strings) {
+					g_assert( hfinfo->display >= BASE_NONE && hfinfo->display < BASE_MAX );
 					fill_label_enumerated_bitfield(fi, label_str);
 				}
 				else {
@@ -1231,16 +1351,20 @@
 	bitwidth = hfinfo_bitwidth(hfinfo);
 
 	/* Pick the proper format string */
+	g_assert( hfinfo->display >= BASE_NONE && hfinfo->display < BASE_MAX );
 	format = hfinfo_uint_vals_format(hfinfo);
 
 	/* Un-shift bits */
@@ -1650,6 +1774,9 @@
 
 		case FT_IPv6:
 			return 16;
+
+		default:
+			g_assert( 0 ); /* not handled */
 	}
 	g_assert_not_reached();
 	return -1;
Index: proto.h
===================================================================
RCS file: /cvsroot/ethereal/proto.h,v
retrieving revision 1.30
diff -u -r1.30 proto.h
--- proto.h	2000/05/11 08:15:59	1.30
+++ proto.h	2000/05/12 10:17:01
@@ -90,7 +91,8 @@
 	BASE_DEC,
 	BASE_HEX,
 	BASE_OCT,
-	BASE_BIN
+	BASE_BIN,
+	BASE_MAX
 };
 
 
Index: tvbuff.c
===================================================================
RCS file: /cvsroot/ethereal/tvbuff.c,v
retrieving revision 1.1
diff -u -r1.1 tvbuff.c
--- tvbuff.c	2000/05/11 08:16:00	1.1
+++ tvbuff.c	2000/05/12 10:17:09
@@ -37,6 +37,7 @@
 #include "tvbuff.h"
 #endif
 
+#include <stdio.h>
 #include <string.h>
 
 /* Pointer versions of ntohs and ntohl.  Given a pointer to a member of a
--
Leedsnet - The information resource for Leeds and the West Riding
< URL:http://www.leedsnet.com/mobile/ >