From ea4f41fb5a834488fefaed867929bc25e688fa1f Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Wed, 8 Jun 2016 11:12:48 -0700 Subject: Check whether cf_info->shb is null before using it. Fixes CID 1362571. Change-Id: I8cb930bade47653d172f8c2057e3bfc446f4e9af Reviewed-on: https://code.wireshark.org/review/15781 Reviewed-by: Guy Harris --- capinfos.c | 140 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 72 insertions(+), 68 deletions(-) (limited to 'capinfos.c') diff --git a/capinfos.c b/capinfos.c index 55554ae8da..10207dcfe9 100644 --- a/capinfos.c +++ b/capinfos.c @@ -694,36 +694,38 @@ print_stats(const gchar *filename, capture_info *cf_info) #endif /* HAVE_LIBGCRYPT */ if (cap_order) printf ("Strict time order: %s\n", order_string(cf_info->order)); - if (cap_comment) { - GArray *opts; - unsigned int i; - - wtap_optionblock_get_string_options(cf_info->shb, OPT_COMMENT, &opts); - for (i = 0; i < opts->len; i++) { - show_option_string("Capture comment: ", g_array_index(opts, char *, i)); + if (cf_info->shb != NULL) { + if (cap_comment) { + GArray *opts; + unsigned int i; + + wtap_optionblock_get_string_options(cf_info->shb, OPT_COMMENT, &opts); + for (i = 0; i < opts->len; i++) { + show_option_string("Capture comment: ", g_array_index(opts, char *, i)); + } + g_array_free(opts, TRUE); + } + if (cap_file_more_info) { + char *str; + + wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_HARDWARE, &str); + show_option_string("Capture hardware: ", str); + wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_OS, &str); + show_option_string("Capture oper-sys: ", str); + wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_USERAPPL, &str); + show_option_string("Capture application: ", str); } - g_array_free(opts, TRUE); - } - if (cap_file_more_info) { - char *str; - - wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_HARDWARE, &str); - show_option_string("Capture hardware: ", str); - wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_OS, &str); - show_option_string("Capture oper-sys: ", str); - wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_USERAPPL, &str); - show_option_string("Capture application: ", str); - } - if (cap_file_idb && cf_info->num_interfaces != 0) { - guint i; - g_assert(cf_info->num_interfaces == cf_info->idb_info_strings->len); - printf ("Number of interfaces in file: %u\n", cf_info->num_interfaces); - for (i = 0; i < cf_info->idb_info_strings->len; i++) { - gchar *s = g_array_index(cf_info->idb_info_strings, gchar*, i); - printf ("Interface #%u info:\n", i); - printf ("%s", s); - printf (" Number of packets = %u\n", cf_info->interface_ids[i]); + if (cap_file_idb && cf_info->num_interfaces != 0) { + guint i; + g_assert(cf_info->num_interfaces == cf_info->idb_info_strings->len); + printf ("Number of interfaces in file: %u\n", cf_info->num_interfaces); + for (i = 0; i < cf_info->idb_info_strings->len; i++) { + gchar *s = g_array_index(cf_info->idb_info_strings, gchar*, i); + printf ("Interface #%u info:\n", i); + printf ("%s", s); + printf (" Number of packets = %u\n", cf_info->interface_ids[i]); + } } } } @@ -966,52 +968,54 @@ print_stats_table(const gchar *filename, capture_info *cf_info) putquote(); } - /* - * this is silly to put into a table format, but oh well - * note that there may be *more than one* of each of these types - * of options - */ - if (cap_comment) { - GArray *opts; - unsigned int i; + if (cf_info->shb != NULL) { + /* + * this is silly to put into a table format, but oh well + * note that there may be *more than one* of each of these types + * of options + */ + if (cap_comment) { + GArray *opts; + unsigned int i; + + wtap_optionblock_get_string_options(cf_info->shb, OPT_COMMENT, &opts); + for (i = 0; i < opts->len; i++) { + const char *opt_comment = g_array_index(opts, char *, i); + + if (opt_comment != NULL) { + putsep(); + putquote(); + printf("%s", opt_comment); + putquote(); + } + } + g_array_free(opts, TRUE); + } - wtap_optionblock_get_string_options(cf_info->shb, OPT_COMMENT, &opts); - for (i = 0; i < opts->len; i++) { - const char *opt_comment = g_array_index(opts, char *, i); + if (cap_file_more_info) { + char *str; - if (opt_comment != NULL) { + wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_HARDWARE, &str); + if (str != NULL) { putsep(); putquote(); - printf("%s", opt_comment); + printf("%s", str); + putquote(); + } + wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_OS, &str); + if (str != NULL) { + putsep(); + putquote(); + printf("%s", str); + putquote(); + } + wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_USERAPPL, &str); + if (str != NULL) { + putsep(); + putquote(); + printf("%s", str); putquote(); } - } - g_array_free(opts, TRUE); - } - - if (cap_file_more_info) { - char *str; - - wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_HARDWARE, &str); - if (str != NULL) { - putsep(); - putquote(); - printf("%s", str); - putquote(); - } - wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_OS, &str); - if (str != NULL) { - putsep(); - putquote(); - printf("%s", str); - putquote(); - } - wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_USERAPPL, &str); - if (str != NULL) { - putsep(); - putquote(); - printf("%s", str); - putquote(); } } -- cgit v1.2.1