From 6d8661ceef654b7857caff35f27b71ec364f7f1d Mon Sep 17 00:00:00 2001 From: Christoph Wurm Date: Sun, 29 Oct 2017 01:33:46 +0000 Subject: Fix segfault in Elasticsearch output When using the Elasticsearch output but only printing the packet summary with -P a segfault will occur because the empty packet tree is not properly handled in this case. Change-Id: I0c91314ae013785ae6dceabd6af33db4b836d1b2 Reviewed-on: https://code.wireshark.org/review/24153 Petri-Dish: Alexis La Goutte Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- epan/print.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/epan/print.c b/epan/print.c index 8fa2ce8e76..941184b6ef 100644 --- a/epan/print.c +++ b/epan/print.c @@ -380,24 +380,28 @@ write_ek_proto_tree(output_fields_t* fields, if (print_summary) write_ek_summary(edt->pi.cinfo, fh); - fprintf(fh, ", \"layers\" : {"); - - if (fields == NULL || fields->fields == NULL) { - /* Write out all fields */ - data.level = 0; - data.fh = fh; - data.src_list = edt->pi.data_src; - data.filter = protocolfilter; - data.filter_flags = protocolfilter_flags; - data.print_hex = print_hex; + if (edt->tree) { + fprintf(fh, ", \"layers\" : {"); + + if (fields == NULL || fields->fields == NULL) { + /* Write out all fields */ + data.level = 0; + data.fh = fh; + data.src_list = edt->pi.data_src; + data.filter = protocolfilter; + data.filter_flags = protocolfilter_flags; + data.print_hex = print_hex; + + proto_tree_write_node_ek(edt->tree, &data); + } else { + /* Write out specified fields */ + write_specified_fields(FORMAT_EK, fields, edt, NULL, fh); + } - proto_tree_write_node_ek(edt->tree, &data); - } else { - /* Write out specified fields */ - write_specified_fields(FORMAT_EK, fields, edt, NULL, fh); + fputs("}", fh); } - fputs("}}\n", fh); + fputs("}\n", fh); } void -- cgit v1.2.3