From 60a926dc32dfc5333961752e902c19d83b98d2ca Mon Sep 17 00:00:00 2001 From: Dario Lombardo Date: Sat, 22 Oct 2016 21:13:14 +0200 Subject: [PATCH] pop: use ws_strtoi function. Change-Id: Icaaa73a0dc9e0ffb7a1c37de9138857c45dcc56c Reviewed-on: https://code.wireshark.org/review/18400 Petri-Dish: Dario Lombardo Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu --- epan/dissectors/packet-pop.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/epan/dissectors/packet-pop.c b/epan/dissectors/packet-pop.c index 63da2c167f..efb963bb8c 100644 --- a/epan/dissectors/packet-pop.c +++ b/epan/dissectors/packet-pop.c @@ -34,8 +34,11 @@ #include #include #include +#include #include +#include + #include "packet-ssl.h" #include "packet-ssl-utils.h" @@ -65,6 +68,8 @@ static int hf_pop_data_fragment_count = -1; static int hf_pop_data_reassembled_in = -1; static int hf_pop_data_reassembled_length = -1; +static expert_field ei_pop_resp_tot_len_invalid = EI_INIT; + static gint ett_pop = -1; static gint ett_pop_reqresp = -1; @@ -289,10 +294,12 @@ dissect_pop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) if (data_val->msg_request) { /* this is a response to a RETR or TOP command */ - if (g_ascii_strncasecmp(line, "+OK ", 4) == 0) { + if (g_ascii_strncasecmp(line, "+OK ", 4) == 0 && strlen(line) > 4) { /* the message will be sent - work out how many bytes */ data_val->msg_read_len = 0; - data_val->msg_tot_len = atoi(line + 4); + data_val->msg_tot_len = 0; + if (sscanf(line, "%*s %u %*s", &data_val->msg_tot_len) != 1) + expert_add_info(pinfo, ti, &ei_pop_resp_tot_len_invalid); } data_val->msg_request = FALSE; } @@ -378,6 +385,8 @@ static void pop_data_reassemble_cleanup (void) void proto_register_pop(void) { + expert_module_t* expert_pop; + static hf_register_info hf[] = { { &hf_pop_response, { "Response", "pop.response", @@ -439,6 +448,11 @@ proto_register_pop(void) NULL, 0x00, "The total length of the reassembled payload", HFILL } }, }; + static ei_register_info ei[] = { + { &ei_pop_resp_tot_len_invalid, { "pop.response.tot_len.invalid", PI_MALFORMED, PI_ERROR, + "Length must be a string containing an integer", EXPFILL }} + }; + static gint *ett[] = { &ett_pop, &ett_pop_reqresp, @@ -463,6 +477,9 @@ proto_register_pop(void) "Whether the POP dissector should reassemble RETR and TOP responses and spanning multiple TCP segments." " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.", &pop_data_desegment); + + expert_pop = expert_register_protocol(proto_pop); + expert_register_field_array(expert_pop, ei, array_length(ei)); } void