Ethereal-dev: [Ethereal-dev] Patch: enable explicit GIOP dissectors

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

From: "W. Borgert" <debacle@xxxxxxxxxx>
Date: Sun, 9 Apr 2006 18:21:46 +0000
Hi,

the attached patch enables the explicit GIOP dissection. This
fixes erronous decoding, if methods of two different CORBA
interfaces have the same name, which happens frequently.

The generated GIOP plugins (CosEvent, CosNaming, Parlay, Tango)
need to be re-generated to make use of the fix.

Cheers,
-- 
W. Borgert <debacle@xxxxxxxxxx>, http://people.debian.org/~debacle/
diff -uraN ethereal.orig/epan/dissectors/packet-giop.c ethereal/epan/dissectors/packet-giop.c
--- ethereal.orig/epan/dissectors/packet-giop.c	2006-04-09 17:41:26.000000000 +0000
+++ ethereal/epan/dissectors/packet-giop.c	2006-04-09 17:01:49.000000000 +0000
@@ -1302,7 +1302,7 @@
 
   if (fp == NULL) {
     if (errno == EACCES)
-      fprintf(stderr, "Error opening file IOR.txt for reading: %s\n",strerror(errno));
+      fprintf(stderr, "Error opening file %s for reading: %s\n", name, strerror(errno));
     return;
   }
 
@@ -2751,7 +2751,8 @@
 
 static void
 dissect_target_address(tvbuff_t * tvb, packet_info *pinfo, int *offset, proto_tree * tree,
-		       gboolean stream_is_big_endian)
+		       gboolean stream_is_big_endian, guint32 *object_key_len,
+		       gchar **object_key_val)
 {
    guint16 discriminant;
    gchar *object_key;
@@ -2759,6 +2760,7 @@
    guint32 len = 0;
    guint32 u_octet4;
 
+   object_key = NULL;
    discriminant = get_CDR_ushort(tvb, offset, stream_is_big_endian,GIOP_HEADER_SIZE);
    if(tree)
    {
@@ -2787,7 +2789,14 @@
 					       "KeyAddr (object key): %s", p_object_key);
 		       }
 		     g_free( p_object_key );
-		     g_free( object_key );
+		     if (object_key_len) {
+		       *object_key_len = len;
+		     }
+		     if (object_key_val) {
+		       *object_key_val = object_key;
+		     } else {
+		       g_free( object_key );
+		     }
 		   }
 		   break;
            case 1: /* ProfileAddr */
@@ -3443,8 +3452,9 @@
   proto_item *tf;
   gboolean exres = FALSE;		/* result of trying explicit dissectors */
 
-  gchar *repoid = NULL;
-
+  guint32 objkey_len = 0;	/* object key length */
+  gchar *objkey = NULL;		/* object key sequence */
+  gchar *repoid = NULL;		/* from object key lookup in objkey hash */
 
   if (tree)
     {
@@ -3481,7 +3491,12 @@
    }
   g_free(reserved);
 
-  dissect_target_address(tvb, pinfo, &offset, request_tree, stream_is_big_endian);
+  dissect_target_address(tvb, pinfo, &offset, request_tree, stream_is_big_endian,
+			 &objkey_len, &objkey);
+  if (objkey) {
+    repoid = get_repoid_from_objkey(giop_objkey_hash, objkey, objkey_len);
+    g_free(objkey);
+  }
 
   /* length of operation string */
   len = get_CDR_string(tvb, &operation, &offset, stream_is_big_endian,GIOP_HEADER_SIZE);
@@ -3541,12 +3556,9 @@
    * fails, try the heuristic method.
    */
 
-
-  /* Comment out to please Coverity, See TODO item 43?
   if(repoid) {
     exres = try_explicit_giop_dissector(tvb,pinfo,tree,&offset,header,operation,repoid);
   }
-  */
 
   /* Only call heuristic if no explicit dissector was found */
 
@@ -3633,8 +3645,7 @@
   else     /* GIOP 1.2 and higher */
   {
       dissect_target_address(tvb, pinfo, &offset, locate_request_tree,
-			     stream_is_big_endian);
-
+			     stream_is_big_endian, NULL, NULL);
   }
 }
 
diff -uraN ethereal.orig/ethereal_gen.py ethereal/ethereal_gen.py
--- ethereal.orig/ethereal_gen.py	2006-04-09 17:39:50.000000000 +0000
+++ ethereal/ethereal_gen.py	2006-04-09 17:39:38.000000000 +0000
@@ -846,9 +846,10 @@
 
     def genOpDelegator(self,oplist):
         for op in oplist:
+            iname = "/".join(op.scopedName()[:-1])
             opname = op.identifier()
             sname = self.namespace(op, "_")
-            self.st.out(self.template_op_delegate_code, sname=sname)
+            self.st.out(self.template_op_delegate_code, interface=iname, sname=sname)
 
     #
     # Delegator for Attributes
@@ -1657,13 +1658,11 @@
 """
 
     template_proto_reg_handoff_body = """
-#if 0
 
 /* Register for Explicit Dissection */
 
 register_giop_user_module(dissect_@dissector_name@, \"@protocol_name@\", \"@interface@\", proto_@dissector_name@ );     /* explicit dissector */
 
-#endif
 
 """
 
@@ -1793,7 +1792,8 @@
     #
 
     template_op_delegate_code = """\
-if (strcmp(operation, @sname@_op) == 0) {
+if (strcmp(operation, @sname@_op) == 0
+    && (!idlname || strcmp(idlname, \"@interface@\") == 0)) {
    tree = start_dissecting(tvb, pinfo, ptree, offset);
    decode_@sname@(tvb, pinfo, tree, offset, header, operation);
    return TRUE;
@@ -2256,7 +2256,7 @@
     return tree;
 }
 
-static gboolean dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, gchar *operation, gchar *idlname _U_) {
+static gboolean dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, gchar *operation, gchar *idlname) {
 
     gboolean be;                        /* big endianess */
     proto_tree *tree _U_;