From 4713ce4476cadb2d4a8869dd2e6f19547841aa9a Mon Sep 17 00:00:00 2001 From: Pascal Quantin Date: Tue, 26 Jul 2016 13:58:55 +0200 Subject: [PATCH] Ensure to have a valid string pointer when writing OS SHB option Change-Id: Ib0b6dcdf1700e88383d30bf43739312fce10e1c7 Reviewed-on: https://code.wireshark.org/review/16696 Petri-Dish: Pascal Quantin Tested-by: Petri Dish Buildbot Reviewed-by: Pascal Quantin --- ui/gtk/file_import_dlg.c | 7 ++++++- ui/tap_export_pdu.c | 7 ++++++- wiretap/merge.c | 9 +++++++-- wiretap/nettrace_3gpp_32_423.c | 7 ++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/ui/gtk/file_import_dlg.c b/ui/gtk/file_import_dlg.c index dc6a97a4f5..09e319126a 100644 --- a/ui/gtk/file_import_dlg.c +++ b/ui/gtk/file_import_dlg.c @@ -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. diff --git a/ui/tap_export_pdu.c b/ui/tap_export_pdu.c index 02cd3df33f..fec86cff1d 100644 --- a/ui/tap_export_pdu.c +++ b/ui/tap_export_pdu.c @@ -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. diff --git a/wiretap/merge.c b/wiretap/merge.c index 89887ffee6..4c14b1efaf 100644 --- a/wiretap/merge.c +++ b/wiretap/merge.c @@ -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. */ diff --git a/wiretap/nettrace_3gpp_32_423.c b/wiretap/nettrace_3gpp_32_423.c index fa3d513603..5495476af7 100644 --- a/wiretap/nettrace_3gpp_32_423.c +++ b/wiretap/nettrace_3gpp_32_423.c @@ -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