giop: don't use packet scope for allocating a buffer at init time.
authorGuy Harris <gharris@sonic.net>
Thu, 5 Nov 2020 00:37:30 +0000 (16:37 -0800)
committerGuy Harris <gharris@sonic.net>
Thu, 5 Nov 2020 00:38:07 +0000 (16:38 -0800)
You can't use packet scope if you're not dissecting a packet;
read_IOR_strings_from_file() is called from giop_init(), which is called
when a file is opened, not when dissecting a packet.

Use NULL as the scope, which just does a regular allocation, and free
the buffer when we're done.

Expand a comment to indicate that using dissection routines is *also* a
bad idea in code that's not used when dissecting packets.

Fixes #16984.

epan/dissectors/packet-giop.c

index c146090333f191ddf7471d9766230ffdc7938a68..96b9a5427f3576d499c5aca852617ae883af2cd8 100644 (file)
@@ -1542,7 +1542,7 @@ static void read_IOR_strings_from_file(const gchar *name, int max_iorlen) {
     return;
   }
 
-  buf = (gchar *)wmem_alloc0(wmem_packet_scope(), max_iorlen+1);        /* input buf */
+  buf = (gchar *)wmem_alloc0(NULL, max_iorlen+1);        /* input buf */
 
   while ((len = giop_getline(fp, buf, max_iorlen+1)) > 0) {
     my_offset = 0;              /* reset for every IOR read */
@@ -1551,10 +1551,12 @@ static void read_IOR_strings_from_file(const gchar *name, int max_iorlen) {
 
     if (ior_val_len>0) {
 
-      /* XXX - can this throw an exception in this case?  If so, we
-         need to catch it and clean up, but we really shouldn't allow
-         it - or "get_CDR_octet()", or "decode_IOR()" - to throw an
-         exception. */
+      /* XXX - can this code throw an exception?  If so, we need to
+         catch it and clean up, but we really shouldn't allow it - or
+         "get_CDR_octet()", or "decode_IOR()" - to throw an exception.
+
+         Either that, or don't reuse dissector code when we're not
+         dissecting a packet. */
 
       tvb =  tvb_new_real_data(out, ior_val_len, ior_val_len);
 
@@ -1567,6 +1569,8 @@ static void read_IOR_strings_from_file(const gchar *name, int max_iorlen) {
   }
 
   fclose(fp);                   /* be nice */
+
+  wmem_free(NULL, buf);
 }