Ensure to have a valid string pointer when writing OS SHB option
authorPascal Quantin <pascal.quantin@gmail.com>
Tue, 26 Jul 2016 11:58:55 +0000 (13:58 +0200)
committerPascal Quantin <pascal.quantin@gmail.com>
Tue, 26 Jul 2016 13:48:40 +0000 (13:48 +0000)
Change-Id: Ib0b6dcdf1700e88383d30bf43739312fce10e1c7
Reviewed-on: https://code.wireshark.org/review/16696
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
ui/gtk/file_import_dlg.c
ui/tap_export_pdu.c
wiretap/merge.c
wiretap/nettrace_3gpp_32_423.c

index dc6a97a4f52419d8e418a5b557386bec802ed474..09e319126a4f48069ac2dc7576cd872f7226812b 100644 (file)
@@ -465,6 +465,7 @@ file_import_open(text_import_info_t *info)
     wtapng_if_descr_mandatory_t *int_data_mand;
     GString                     *os_info_str;
     gsize                        opt_len;
+    gchar                       *opt_str;
 
     /* Create data for SHB  */
     os_info_str = g_string_new("");
@@ -480,7 +481,11 @@ file_import_open(text_import_info_t *info)
      * this section.
      */
     opt_len = os_info_str->len;
-    wtap_block_add_string_option(shb_hdr, OPT_SHB_OS, g_string_free(os_info_str, TRUE), opt_len);
+    opt_str = g_string_free(os_info_str, FALSE);
+    if (opt_str) {
+        wtap_block_add_string_option(shb_hdr, OPT_SHB_OS, opt_str, opt_len);
+        g_free(opt_str);
+    }
     /*
      * UTF-8 string containing the name of the application used to create
      * this section.
index 02cd3df33fffd7b66c5228ea510b62d0fa8b8af9..fec86cff1d72981470beba3b278249dcd53962a1 100644 (file)
@@ -109,6 +109,7 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
     wtapng_if_descr_mandatory_t *int_data_mand;
     GString                     *os_info_str;
     gsize                        opt_len;
+    gchar                       *opt_str;
 
     /* Create data for SHB  */
     os_info_str = g_string_new("");
@@ -125,7 +126,11 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
      * this section.
      */
     opt_len = os_info_str->len;
-    wtap_block_add_string_option(shb_hdr, OPT_SHB_OS, g_string_free(os_info_str, TRUE), opt_len);
+    opt_str = g_string_free(os_info_str, FALSE);
+    if (opt_str) {
+        wtap_block_add_string_option(shb_hdr, OPT_SHB_OS, opt_str, opt_len);
+        g_free(opt_str);
+    }
     /*
      * UTF-8 string containing the name of the application used to create
      * this section.
index 89887ffee69d7af8900fc6098dce27b9d66dceb5..4c14b1efaf2fed8ecbb06fc9076ad43709886c59 100644 (file)
@@ -372,6 +372,7 @@ create_shb_header(const merge_in_file_t *in_files, const guint in_file_count,
     char* shb_comment = NULL;
     wtapng_mandatory_section_t* shb_data;
     gsize opt_len;
+    gchar *opt_str;
 
     shb_hdrs = wtap_file_get_shb_for_new_file(in_files[0].wth);
     shb_hdr = g_array_index(shb_hdrs, wtap_block_t, 0);
@@ -412,8 +413,12 @@ create_shb_header(const merge_in_file_t *in_files, const guint in_file_count,
      */
     wtap_block_remove_option(shb_hdr, OPT_SHB_HARDWARE);
     opt_len = os_info_str->len;
-    wtap_block_set_string_option_value(shb_hdr, OPT_SHB_OS, g_string_free(os_info_str, FALSE), opt_len); /* UTF-8 string containing the name   */
-                                                                                                            /*  of the operating system used to create this section.     */
+    opt_str = g_string_free(os_info_str, FALSE);
+    if (opt_str) {
+        wtap_block_set_string_option_value(shb_hdr, OPT_SHB_OS, opt_str, opt_len); /* UTF-8 string containing the name   */
+                                                                                   /*  of the operating system used to create this section.     */
+        g_free(opt_str);
+    }
     wtap_block_set_string_option_value(shb_hdr, OPT_SHB_USERAPPL, (char*)app_name, app_name ? strlen(app_name): 0 ); /* NULL if not available, UTF-8 string containing the name */
                                                                                       /*  of the application used to create this section.          */
 
index fa3d513603bff0edbb84abae92bd6d717a0ed944..5495476af7c928efe81b440a996cbfdf8565a9e5 100644 (file)
@@ -729,6 +729,7 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
        int name_str_len;
        char name_str[64];
        gsize opt_len;
+       gchar *opt_str;
        /* Info to build exported_pdu tags*/
        exported_pdu_info_t  exported_pdu_info;
 
@@ -762,7 +763,11 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
        * this section.
        */
        opt_len = os_info_str->len;
-       wtap_block_add_string_option(shb_hdr, OPT_SHB_OS, g_string_free(os_info_str, TRUE), opt_len);
+       opt_str = g_string_free(os_info_str, FALSE);
+       if (opt_str) {
+               wtap_block_add_string_option(shb_hdr, OPT_SHB_OS, opt_str, opt_len);
+               g_free(opt_str);
+       }
 
        /*
        * UTF-8 string containing the name of the application used to create