From Jakub Zawadzki:
authoretxrab <etxrab@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 2 Jan 2010 09:46:16 +0000 (09:46 +0000)
committeretxrab <etxrab@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 2 Jan 2010 09:46:16 +0000 (09:46 +0000)
Cleanup dissector code - use proper memory functions.
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4164

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

epan/dissectors/packet-collectd.c
epan/dissectors/packet-ieee80211.c
epan/dissectors/packet-kerberos.c
epan/dissectors/packet-rpc.c
epan/dissectors/packet-tpncp.c
epan/dissectors/packet-vj.c

index a219953b64257d22ad91d767bb44f5624bdf461b..dcdcc3bc90a085857bfbc04da8b368e085acd5b3 100644 (file)
@@ -822,14 +822,8 @@ stats_account_string (string_counter_t **ret_list, const gchar *new_value)
                        return (0);
                }
 
-       entry = ep_alloc (sizeof (*entry));
-       if (entry == NULL)
-               return (-1);
-       memset (entry, 0, sizeof (*entry));
-
+       entry = ep_alloc0 (sizeof (*entry));
        entry->string = ep_strdup (new_value);
-       if (entry->string == NULL)
-               return (-1);
        entry->count = 1;
        entry->next = *ret_list;
 
index 7316d6187e6c672266f82f0b66092046fe9db6ee..1d740591cc484c329845aa3e11c9b9c2d63d76dd 100644 (file)
@@ -12483,8 +12483,7 @@ static void init_wepkeys(void) {
     wep_keylens[keyidx] = 0;
 
 #ifdef USE_ENV
-    buf=ep_alloc(128);
-    g_snprintf(buf, 128, "WIRESHARK_WEPKEY%d", i+1);
+    buf = ep_strdup_printf("WIRESHARK_WEPKEY%d", i+1);
     tmp = getenv(buf);
 #else
     tmp = wep_keystr[i];
index 11611a2068c5404c035b811a9c83dc35faa86230..03d5fa7b945dbdd906d7d6657b633390dcf65379 100644 (file)
@@ -717,8 +717,7 @@ decrypt_krb5_data(proto_tree *tree, packet_info *pinfo,
                  keys. So just give it a copy of the crypto data instead.
                  This has been seen for RC4-HMAC blobs.
                */
-               cryptocopy=g_malloc(length);
-               memcpy(cryptocopy, cryptotext, length);
+               cryptocopy=g_memdup(cryptotext, length);
                ret = krb5_decrypt_ivec(krb5_ctx, crypto, usage,
                                cryptocopy, length,
                                &data,
@@ -731,8 +730,7 @@ printf("woohoo decrypted keytype:%d in frame:%u\n", ek->keytype, pinfo->fd->num)
                        proto_tree_add_text(tree, NULL, 0, 0, "[Decrypted using: %s]", ek->key_origin);
                        krb5_crypto_destroy(krb5_ctx, crypto);
                        /* return a private g_malloced blob to the caller */
-                       user_data=g_malloc(data.length);
-                       memcpy(user_data, data.data, data.length);
+                       user_data=g_memdup(data.data, data.length);
                        if (datalen) {
                                *datalen = data.length;
                        }
@@ -772,8 +770,7 @@ printf("added key in %u\n",pinfo->fd->num);
        new_key->kvno = 0;
        new_key->keytype = keytype;
        new_key->length = keylength;
-       new_key->contents = g_malloc(keylength);
-       memcpy(new_key->contents, keyvalue, keylength);
+       new_key->contents = g_memdup(keyvalue, keylength);
        g_snprintf(new_key->origin, KRB_MAX_ORIG_LEN, "%s learnt from frame %u", origin, pinfo->fd->num);
        service_key_list = g_slist_append(service_key_list, (gpointer) new_key);
 }
@@ -829,8 +826,7 @@ read_keytab_file(const char *service_key_file)
                        sk->kvno = buf[0] << 8 | buf[1];
                        sk->keytype = KEYTYPE_DES3_CBC_MD5;
                        sk->length = DES3_KEY_SIZE;
-                       sk->contents = g_malloc(DES3_KEY_SIZE);
-                       memcpy(sk->contents, buf + 2, DES3_KEY_SIZE);
+                       sk->contents = g_memdup(buf + 2, DES3_KEY_SIZE);
                        g_snprintf(sk->origin, KRB_MAX_ORIG_LEN, "3DES service key file, key #%d, offset %ld", count, ftell(skf));
                        service_key_list = g_slist_append(service_key_list, (gpointer) sk);
                        fseek(skf, newline_skip, SEEK_CUR);
index 76113a49963d4d033066a3e64cb27615a193f4d9..43617d633d4f48105729df2687a48037dbd5a868 100644 (file)
@@ -609,9 +609,7 @@ dissect_rpc_opaque_data(tvbuff_t *tvb, int offset,
         }
 
        if (string_data) {
-               char *tmpstr;
-               tmpstr = tvb_get_ephemeral_string(tvb, data_offset, string_length_copy);
-               string_buffer = memcpy(ep_alloc(string_length_copy+1), tmpstr, string_length_copy);
+               string_buffer = tvb_get_ephemeral_string(tvb, data_offset, string_length_copy);
        } else {
                string_buffer = tvb_memcpy(tvb, ep_alloc(string_length_copy+1), data_offset, string_length_copy);
        }
@@ -1663,12 +1661,9 @@ rpc_prog_info_value *rpc_prog = NULL;
                        { 0,NULL,NULL,NULL }
                };
 
-               NAME=g_malloc(36);
-               Name=g_malloc(32);
-               name=g_malloc(32);
-               g_snprintf(NAME, 36, "Unknown RPC Program:%d",prpc_prog_key->prog);
-               g_snprintf(Name, 32, "RPC:%d",prpc_prog_key->prog);
-               g_snprintf(name, 32, "rpc%d",prpc_prog_key->prog);
+               NAME = g_strdup_printf("Unknown RPC Program:%d",prpc_prog_key->prog);
+               Name = g_strdup_printf("RPC:%d",prpc_prog_key->prog);
+               name = g_strdup_printf("rpc%d",prpc_prog_key->prog);
                proto_rpc_unknown_program = proto_register_protocol(NAME, Name, name);
 
                rpc_init_prog(proto_rpc_unknown_program, prpc_prog_key->prog, ett_rpc_unknown_program);
index e8426c16d02775612d6f9431360ebcb192a15119..a1200dfdf3a8c5e2f78d908e9152410fef3a421f 100644 (file)
@@ -54,7 +54,6 @@
 #define UDP_PORT_TPNCP_HOST BASE_TPNCP_PORT
 
 #define BASE_TPNCP_DATA_LEN 256
-#define MAX_TPNCP_DAT_FILE_PATH_LEN BASE_TPNCP_DATA_LEN
 #define MAX_TPNCP_DB_ENTRY_LEN BASE_TPNCP_DATA_LEN
 
 #define MAX_TPNCP_DB_SIZE 3000
@@ -682,12 +681,10 @@ static gint init_tpncp_data_fields_info(tpncp_data_field_info *data_fields_info,
 /*-------------------------------------------------------------------------------------------------------------------------------------------*/
 
 static gint init_tpncp_db(void) {
-    gchar *tpncp_dat_file_path = NULL;
-    FILE *file = NULL;
+    gchar *tpncp_dat_file_path;
+    FILE *file;
 
-    tpncp_dat_file_path = ep_alloc(MAX_TPNCP_DAT_FILE_PATH_LEN);
-    tpncp_dat_file_path[0] = 0;
-    g_snprintf(tpncp_dat_file_path, MAX_TPNCP_DAT_FILE_PATH_LEN, "%s" G_DIR_SEPARATOR_S"tpncp" G_DIR_SEPARATOR_S "tpncp.dat", get_datafile_dir());
+    tpncp_dat_file_path = ep_strdup_printf("%s" G_DIR_SEPARATOR_S"tpncp" G_DIR_SEPARATOR_S "tpncp.dat", get_datafile_dir());
 
     /* Open file with TPNCP data. */
     if ((file = ws_fopen(tpncp_dat_file_path, "r")) == NULL)
index 1ed19c2e4dc3b25ed5c14a8e1f54ba4329b452fa..62e82f274a212ec05a32ea2e349f76ef2c81ff49 100644 (file)
@@ -450,11 +450,9 @@ vj_init(void)
 static slcompress *
 slhc_init(void)
 {
-  slcompress *comp = se_alloc(sizeof(slcompress));
+  slcompress *comp = se_alloc0(sizeof(slcompress));
   int         i;
 
-  memset(comp, ZERO, sizeof(slcompress));
-
   /*
    * Initialize the state; there is no current connection, and
    * we have no header data for any of the connections, as we