Fix tvb memory leak; Add missing call to add_new_data_source();
authorwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 16 Dec 2011 00:33:03 +0000 (00:33 +0000)
committerwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 16 Dec 2011 00:33:03 +0000 (00:33 +0000)
Also: remove unneeded #includes.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@40221 f5534014-38df-0310-8fa8-9805f1628bb7

epan/dissectors/packet-dtls.c
epan/dissectors/packet-ssl-utils.c
epan/dissectors/packet-ssl-utils.h
epan/dissectors/packet-ssl.c

index fbb292e3644861daed351b3d06e8f032b08aa766..1f36ec7567b0fbb6b0e5d40f09dfc4e1bfcbc560 100644 (file)
@@ -763,7 +763,7 @@ dissect_dtls_record(tvbuff_t *tvb, packet_info *pinfo,
                             dtls_decrypted_data_avail, offset);
 
       /* try to retrive and use decrypted alert record, if any. */
-      decrypted = ssl_get_record_info(proto_dtls, pinfo, offset);
+      decrypted = ssl_get_record_info(tvb, proto_dtls, pinfo, offset);
       if (decrypted)
         dissect_dtls_alert(decrypted, pinfo, dtls_record_tree, 0,
                            conv_version);
@@ -786,7 +786,7 @@ dissect_dtls_record(tvbuff_t *tvb, packet_info *pinfo,
                             dtls_decrypted_data_avail, offset);
 
       /* try to retrive and use decrypted handshake record, if any. */
-      decrypted = ssl_get_record_info(proto_dtls, pinfo, offset);
+      decrypted = ssl_get_record_info(tvb, proto_dtls, pinfo, offset);
       if (decrypted)
         dissect_dtls_handshake(decrypted, pinfo, dtls_record_tree, 0,
                                tvb_length(decrypted), conv_version, ssl, content_type);
index cd6bba2e9e43348fe360eaff91acf5fba736ed81..a81fb8bd3f34cbf0a33f0bf4539d58ce983fa426 100644 (file)
 # include "config.h"
 #endif
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #ifdef HAVE_LIBZ
 #include <zlib.h>
 #endif
@@ -3052,36 +3048,37 @@ ssl_packet_from_server(SslDecryptSession* ssl, GTree* associations, packet_info
     return ret;
 }
 
-/* add to packet data a newly allocated tvb with the specified real data*/
+/* add to packet data a copy of the specified real data */
 void
 ssl_add_record_info(gint proto, packet_info *pinfo, guchar* data, gint data_len, gint record_id)
 {
     guchar* real_data;
     SslRecordInfo* rec;
     SslPacketInfo* pi;
-    real_data = se_alloc(data_len);
-    rec = se_alloc(sizeof(SslRecordInfo));
-    pi = p_get_proto_data(pinfo->fd, proto);
 
+    pi = p_get_proto_data(pinfo->fd, proto);
     if (!pi)
     {
         pi = se_alloc0(sizeof(SslPacketInfo));
-        p_add_proto_data(pinfo->fd, proto,pi);
+        p_add_proto_data(pinfo->fd, proto, pi);
     }
 
-    rec->id = record_id;
-    rec->tvb = tvb_new_real_data(real_data, data_len, data_len);
+    real_data = se_alloc(data_len);
     memcpy(real_data, data, data_len);
 
+    rec = se_alloc(sizeof(SslRecordInfo));
+    rec->id = record_id;
+    rec->real_data = real_data;
+    rec->data_len = data_len;
+
     /* head insertion */
     rec->next= pi->handshake_data;
     pi->handshake_data = rec;
 }
 
-
-/* search in packet data the tvbuff associated to the specified id */
+/* search in packet data for the specified id; return a newly created tvb for the associated data */
 tvbuff_t*
-ssl_get_record_info(int proto, packet_info *pinfo, gint record_id)
+ssl_get_record_info(tvbuff_t *parent_tvb, int proto, packet_info *pinfo, gint record_id)
 {
     SslRecordInfo* rec;
     SslPacketInfo* pi;
@@ -3092,7 +3089,8 @@ ssl_get_record_info(int proto, packet_info *pinfo, gint record_id)
 
     for (rec = pi->handshake_data; rec; rec = rec->next)
         if (rec->id == record_id)
-            return rec->tvb;
+            /* link new real_data_tvb with a parent tvb so it is freed when frame dissection is complete */
+            return tvb_new_child_real_data(parent_tvb, rec->real_data, rec->data_len, rec->data_len);
 
     return NULL;
 }
index 6b02293ba554b1573338e5458eebecf6190a3886..3bb99c77a695927d7394d1e775e220d607848bfc 100644 (file)
@@ -30,8 +30,6 @@
 #include <epan/packet.h>
 #include <epan/emem.h>
 
-#include <stdio.h>
-
 #ifdef HAVE_LIBGNUTLS
 #include <gcrypt.h>
 #include <gnutls/x509.h>
@@ -214,17 +212,17 @@ typedef struct _StringInfo {
 #define SSLV2_MAX_SESSION_ID_LENGTH_IN_BYTES 16
 
 typedef struct _SslCipherSuite {
-     gint number;
-     gint kex;
-     gint sig;
-     gint enc;
-     gint block;
-     gint bits;
-     gint eff_bits;
-     gint dig;
-     gint dig_len;
-     gint export;
-     gint mode;
+    gint number;
+    gint kex;
+    gint sig;
+    gint enc;
+    gint block;
+    gint bits;
+    gint eff_bits;
+    gint dig;
+    gint dig_len;
+    gint export;
+    gint mode;
 } SslCipherSuite;
 
 typedef struct _SslFlow {
@@ -267,10 +265,9 @@ typedef struct _SslDecoder {
 #define DIG_MD5         0x40
 #define DIG_SHA         0x41
 
-struct tvbuff;
-
 typedef struct _SslRecordInfo {
-    struct tvbuff* tvb;
+    guchar *real_data;
+    gint data_len;
     gint id;
     struct _SslRecordInfo* next;
 } SslRecordInfo;
@@ -326,24 +323,24 @@ typedef struct _SslDecryptSession {
 } SslDecryptSession;
 
 typedef struct _SslAssociation {
-  gboolean tcp;
-  guint ssl_port;
-  dissector_handle_t handle;
-  gchar* info;
-  gboolean from_key_list;
+    gboolean tcp;
+    guint ssl_port;
+    dissector_handle_t handle;
+    gchar* info;
+    gboolean from_key_list;
 } SslAssociation;
 
 typedef struct _SslService {
-  address addr;
-  guint port;
+    address addr;
+    guint port;
 } SslService;
 
 typedef struct _Ssl_private_key {
 #ifdef HAVE_LIBGNUTLS
-  gnutls_x509_crt_t     x509_cert;
-  gnutls_x509_privkey_t x509_pkey;
+    gnutls_x509_crt_t     x509_cert;
+    gnutls_x509_privkey_t x509_pkey;
 #endif
-  SSL_PRIVATE_KEY       *sexp_pkey;
+    SSL_PRIVATE_KEY       *sexp_pkey;
 } Ssl_private_key_t;
 
 /* User Access Table */
@@ -403,7 +400,7 @@ ssl_free_key(Ssl_private_key_t* key);
 extern gint
 ssl_find_private_key(SslDecryptSession *ssl_session, GHashTable *key_hash, GTree* associations, packet_info *pinfo);
 
-/** Search for the specified cipher souite id
+/** Search for the specified cipher suite id
  @param num the id of the cipher suite to be searched
  @param cs pointer to the cipher suite struct to be filled
  @return 0 if the cipher suite is found, -1 elsewhere */
@@ -493,13 +490,13 @@ ssl_assoc_from_key_list(gpointer key _U_, gpointer data, gpointer user_data);
 extern gint
 ssl_packet_from_server(SslDecryptSession* ssl, GTree* associations, packet_info *pinfo);
 
-/* add to packet data a newly allocated tvb with the specified real data*/
+/* add to packet data a copy of the specified real data */
 extern void
 ssl_add_record_info(gint proto, packet_info *pinfo, guchar* data, gint data_len, gint record_id);
 
-/* search in packet data the tvbuff associated to the specified id */
+/* search in packet data for the specified id; return a newly created tvb for the associated data */
 extern tvbuff_t*
-ssl_get_record_info(gint proto, packet_info *pinfo, gint record_id);
+ssl_get_record_info(tvbuff_t *parent_tvb, gint proto, packet_info *pinfo, gint record_id);
 
 void
 ssl_add_data_info(gint proto, packet_info *pinfo, guchar* data, gint data_len, gint key, SslFlow *flow);
index 477da3ea1b249322a98b645b6706f8a3de19e7ea..dffcde2a6dd084138dc4e7a80fff5a2455930a1f 100644 (file)
@@ -1567,11 +1567,13 @@ dissect_ssl3_record(tvbuff_t *tvb, packet_info *pinfo,
                   ssl_decrypted_data_avail, offset);
 
         /* try to retrieve and use decrypted alert record, if any. */
-        decrypted = ssl_get_record_info(proto_ssl, pinfo, offset);
-        if (decrypted)
-          dissect_ssl3_alert(decrypted, pinfo, ssl_record_tree, 0, conv_version);
-        else
-          dissect_ssl3_alert(tvb, pinfo, ssl_record_tree, offset, conv_version);
+        decrypted = ssl_get_record_info(tvb, proto_ssl, pinfo, offset);
+        if (decrypted) {
+            add_new_data_source(pinfo, decrypted, "Decrypted SSL record");
+            dissect_ssl3_alert(decrypted, pinfo, ssl_record_tree, 0, conv_version);
+        } else {
+            dissect_ssl3_alert(tvb, pinfo, ssl_record_tree, offset, conv_version);
+        }
         break;
     }
     case SSL_ID_HANDSHAKE:
@@ -1588,7 +1590,7 @@ dissect_ssl3_record(tvbuff_t *tvb, packet_info *pinfo,
                 ssl_decrypted_data_avail, offset);
 
         /* try to retrieve and use decrypted handshake record, if any. */
-        decrypted = ssl_get_record_info(proto_ssl, pinfo, offset);
+        decrypted = ssl_get_record_info(tvb, proto_ssl, pinfo, offset);
         if (decrypted) {
             /* add desegmented data to the data source list */
             add_new_data_source(pinfo, decrypted, "Decrypted SSL record");