diff options
author | Guy Harris <guy@alum.mit.edu> | 2019-07-16 15:08:02 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2019-07-16 22:48:19 +0000 |
commit | d699c5d84c498b4a853b64ff2826ff5504eaf096 (patch) | |
tree | 406abd481557a5f28add9c5d9d3d4cdf1ee883e6 /epan/dissectors/packet-distcc.c | |
parent | a754879c7d3ebaa1cb18e2d20082556652f62556 (diff) |
Clean up handling of the command parameter.
It's an unsigned int, as per the protocol spec. Treat it as such. (Add
a URL for the protocol spec while we're at it.)
Convert it from a string of ASCII hex digits to a number using
ws_hexstrtou32(); that routine does the appropriate checks.
Clean up blank lines while we're at it - add some and remove some.
Change-Id: I2c0832c4a57c121e2e64de49a8678b747025f35e
Reviewed-on: https://code.wireshark.org/review/33972
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/dissectors/packet-distcc.c')
-rw-r--r-- | epan/dissectors/packet-distcc.c | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/epan/dissectors/packet-distcc.c b/epan/dissectors/packet-distcc.c index fe4594afd3..a36502bed8 100644 --- a/epan/dissectors/packet-distcc.c +++ b/epan/dissectors/packet-distcc.c @@ -9,16 +9,20 @@ * * SPDX-License-Identifier: GPL-2.0-or-later */ -/* This dissector supports version 1 of the DISTCC protocol */ -#include "config.h" +/* + * This dissector supports version 1 of the DISTCC protocol: + * + * https://github.com/distcc/distcc/blob/master/doc/protocol-1.txt + */ -#include <stdio.h> +#include "config.h" #include <epan/packet.h> #include <epan/expert.h> #include <epan/prefs.h> +#include <wsutil/strtoi.h> static int proto_distcc = -1; static int hf_distcc_version = -1; @@ -45,7 +49,7 @@ void proto_register_distcc(void); extern void proto_reg_handoff_distcc(void); #define CHECK_PDU_LEN(x) \ - if(parameter>tvb_captured_length_remaining(tvb, offset) || parameter < 1){\ + if(parameter>(guint)tvb_captured_length_remaining(tvb, offset) || parameter < 1){\ len=tvb_captured_length_remaining(tvb, offset);\ col_append_str(pinfo->cinfo, COL_INFO, "[Short" x " PDU]");\ } \ @@ -56,7 +60,7 @@ extern void proto_reg_handoff_distcc(void); if(distcc_desegment && pinfo->can_desegment){\ /* only attempt reassembly if we have the full segment */\ if(tvb_captured_length_remaining(tvb, offset)==tvb_reported_length_remaining(tvb, offset)){\ - if(parameter>tvb_captured_length_remaining(tvb, offset)){\ + if(parameter>(guint)tvb_captured_length_remaining(tvb, offset)){\ proto_tree_add_expert_format(tree, pinfo, &ei_distcc_short_pdu, tvb, offset-12, -1, "[Short " x " PDU]");\ pinfo->desegment_offset=offset-12;\ pinfo->desegment_len=parameter-tvb_captured_length_remaining(tvb, offset);\ @@ -65,16 +69,12 @@ extern void proto_reg_handoff_distcc(void); }\ } - - - - static int dissect_distcc_dist(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint32 parameter) { - proto_tree_add_uint_format(tree, hf_distcc_version, tvb, offset-12, 12, parameter, "DIST: %d", parameter); + proto_tree_add_uint_format(tree, hf_distcc_version, tvb, offset-12, 12, parameter, "DIST: %u", parameter); - col_append_fstr(pinfo->cinfo, COL_INFO, "DIST:%d ", parameter); + col_append_fstr(pinfo->cinfo, COL_INFO, "DIST:%u ", parameter); return offset; } @@ -82,9 +82,9 @@ dissect_distcc_dist(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int off static int dissect_distcc_done(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint32 parameter) { - proto_tree_add_uint_format(tree, hf_distcc_version, tvb, offset-12, 12, parameter, "DONE: %d", parameter); + proto_tree_add_uint_format(tree, hf_distcc_version, tvb, offset-12, 12, parameter, "DONE: %u", parameter); - col_append_fstr(pinfo->cinfo, COL_INFO, "DONE:%d ", parameter); + col_append_fstr(pinfo->cinfo, COL_INFO, "DONE:%u ", parameter); return offset; } @@ -92,9 +92,9 @@ dissect_distcc_done(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int off static int dissect_distcc_stat(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint32 parameter) { - proto_tree_add_uint_format(tree, hf_distcc_stat, tvb, offset-12, 12, parameter, "STAT: %d", parameter); + proto_tree_add_uint_format(tree, hf_distcc_stat, tvb, offset-12, 12, parameter, "STAT: %u", parameter); - col_append_fstr(pinfo->cinfo, COL_INFO, "STAT:%d ", parameter); + col_append_fstr(pinfo->cinfo, COL_INFO, "STAT:%u ", parameter); return offset; } @@ -104,17 +104,17 @@ dissect_distcc_argc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int off { proto_tree_add_uint(tree, hf_distcc_argc, tvb, offset-12, 12, parameter); - col_append_fstr(pinfo->cinfo, COL_INFO, "ARGC:%d ", parameter); + col_append_fstr(pinfo->cinfo, COL_INFO, "ARGC:%u ", parameter); return offset; } static int -dissect_distcc_argv(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, gint parameter) +dissect_distcc_argv(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint parameter) { char argv[256]; int argv_len; - gint len=parameter; + gint len=(gint)parameter; proto_item* ti; CHECK_PDU_LEN("ARGV"); @@ -130,18 +130,18 @@ dissect_distcc_argv(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int off col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", argv); - if(len!=parameter){ + if(len!=(gint)parameter){ expert_add_info_format(pinfo, ti, &ei_distcc_short_pdu, "[Short ARGV PDU]"); } return offset+len; } static int -dissect_distcc_serr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, gint parameter) +dissect_distcc_serr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint parameter) { char argv[256]; int argv_len; - gint len=parameter; + gint len=(gint)parameter; proto_item* ti; CHECK_PDU_LEN("SERR"); @@ -149,8 +149,6 @@ dissect_distcc_serr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int off /* see if we need to desegment the PDU */ DESEGMENT_TCP("SERR"); - - argv_len=len>255?255:len; tvb_memcpy(tvb, argv, offset, argv_len); argv[argv_len]=0; @@ -159,18 +157,18 @@ dissect_distcc_serr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int off col_append_fstr(pinfo->cinfo, COL_INFO, "SERR:%s ", argv); - if(len!=parameter){ + if(len!=(gint)parameter){ expert_add_info_format(pinfo, ti, &ei_distcc_short_pdu, "[Short SERR PDU]"); } return offset+len; } static int -dissect_distcc_sout(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, gint parameter) +dissect_distcc_sout(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint parameter) { char argv[256]; int argv_len; - gint len=parameter; + gint len=(gint)parameter; proto_item* ti; CHECK_PDU_LEN("SOUT"); @@ -186,7 +184,7 @@ dissect_distcc_sout(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int off col_append_fstr(pinfo->cinfo, COL_INFO, "SOUT:%s ", argv); - if(len!=parameter){ + if(len!=(gint)parameter){ expert_add_info_format(pinfo, ti, &ei_distcc_short_pdu, "[Short SOUT PDU]"); } return offset+len; @@ -194,9 +192,9 @@ dissect_distcc_sout(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int off static int -dissect_distcc_doti(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, gint parameter) +dissect_distcc_doti(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint parameter) { - gint len=parameter; + gint len=(gint)parameter; proto_item* ti; CHECK_PDU_LEN("DOTI"); @@ -207,19 +205,19 @@ dissect_distcc_doti(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int off col_append_str(pinfo->cinfo, COL_INFO, "DOTI source "); ti = proto_tree_add_item(tree, hf_distcc_doti_source, tvb, offset, len, ENC_ASCII|ENC_NA); - if(len!=parameter){ + + if(len!=(gint)parameter){ expert_add_info_format(pinfo, ti, &ei_distcc_short_pdu, "[Short DOTI PDU]"); } return offset+len; } static int -dissect_distcc_doto(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, gint parameter) +dissect_distcc_doto(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint parameter) { - gint len=parameter; + gint len=(gint)parameter; proto_item* ti; - CHECK_PDU_LEN("DOTO"); /* see if we need to desegment the PDU */ @@ -228,7 +226,8 @@ dissect_distcc_doto(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int off col_append_str(pinfo->cinfo, COL_INFO, "DOTO object "); ti = proto_tree_add_item(tree, hf_distcc_doto_object, tvb, offset, len, ENC_NA); - if(len!=parameter){ + + if(len!=(gint)parameter){ expert_add_info_format(pinfo, ti, &ei_distcc_short_pdu, "[Short DOTO PDU]"); } return offset+len; @@ -263,8 +262,8 @@ dissect_distcc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* buf[12] = '\0'; offset+=12; - /* scan the parameter */ - if (sscanf(buf + 4, "%08x", ¶meter) != 1) + /* get the parameter value */ + if (!ws_hexstrtou32(buf + 4, NULL, ¶meter)) return offset; if(!strncmp(buf, "DIST", 4)){ |