ppp: remove some more unnecessary NULL checks

Change-Id: Icc6a798565d74fa84dae975e424762db9963c1b2
Reviewed-on: https://code.wireshark.org/review/29320
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Martin Kaiser 2018-08-23 23:06:23 +02:00 committed by Anders Broman
parent 9d9a873d9a
commit fb3df8b6a8
1 changed files with 123 additions and 153 deletions

View File

@ -4592,9 +4592,12 @@ dissect_cp(tvbuff_t *tvb, int proto_id, int proto_subtree_index,
dissector_table_t option_table, packet_info *pinfo, proto_tree *tree)
{
proto_item *ti;
proto_tree *fh_tree = NULL;
proto_tree *fh_tree;
guint8 code;
int length, offset;
guint32 oui;
const gchar *manuf;
guint32 secs_remaining;
code = tvb_get_guint8(tvb, 0);
length = tvb_get_ntohs(tvb, 2);
@ -4604,23 +4607,18 @@ dissect_cp(tvbuff_t *tvb, int proto_id, int proto_subtree_index,
col_set_str(pinfo->cinfo, COL_INFO,
val_to_str_const(code, proto_vals, "Unknown"));
if (tree) {
ti = proto_tree_add_item(tree, proto_id, tvb, 0, length, ENC_NA);
fh_tree = proto_item_add_subtree(ti, proto_subtree_index);
proto_tree_add_uint_format_value(fh_tree, hf_ppp_code, tvb, 0, 1, code,
"%s (%u)", val_to_str_const(code, proto_vals, "Unknown"), code);
proto_tree_add_item(fh_tree, hf_ppp_identifier, tvb, 1, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(fh_tree, hf_ppp_length, tvb, 2, 2, ENC_BIG_ENDIAN);
}
offset = 4;
length -= 4;
switch (code) {
case VNDRSPCFC:
if (tree) {
guint32 oui;
const gchar *manuf;
proto_tree_add_item(fh_tree, hf_ppp_magic_number, tvb, offset, 4,
ENC_BIG_ENDIAN);
oui = tvb_get_ntoh24(tvb, offset + 4);
@ -4637,7 +4635,6 @@ dissect_cp(tvbuff_t *tvb, int proto_id, int proto_subtree_index,
proto_tree_add_item(fh_tree, hf_ppp_data, tvb, offset + 8,
length - 8, ENC_NA);
}
}
break;
case CONFREQ:
@ -4654,7 +4651,7 @@ dissect_cp(tvbuff_t *tvb, int proto_id, int proto_subtree_index,
break;
case CODEREJ:
if (tree && (length > 0)) {
if (length > 0) {
/* TODO: Decode the rejected packet here ... but wait until we have
* a valid capture file with a CODEREJ, since the only capture file
* with CODEREJ packets in it that I know of is pppoe.dump.gz from
@ -4669,10 +4666,8 @@ dissect_cp(tvbuff_t *tvb, int proto_id, int proto_subtree_index,
break;
case PROTREJ: /* LCP only: RFC 1661 */
if (tree) {
proto_tree_add_item(fh_tree, hf_lcp_rej_proto, tvb, offset, 2,
ENC_BIG_ENDIAN);
}
if (length > 2) {
gboolean save_in_error_pkt;
tvbuff_t *next_tvb;
@ -4706,31 +4701,24 @@ dissect_cp(tvbuff_t *tvb, int proto_id, int proto_subtree_index,
case ECHOREQ: /* All 3 are LCP only: RFC 1661 */
case ECHOREP:
case DISCREQ:
if (tree) {
proto_tree_add_item(fh_tree, hf_lcp_magic_number, tvb, offset, 4,
ENC_BIG_ENDIAN);
if (length > 4) {
proto_tree_add_item(fh_tree, hf_lcp_data, tvb, offset + 4,
length - 4, ENC_NA);
}
}
break;
case IDENT: /* LCP only: RFC 1570 */
if (tree) {
proto_tree_add_item(fh_tree, hf_lcp_magic_number, tvb, offset, 4,
ENC_BIG_ENDIAN);
if (length > 4) {
proto_tree_add_item(fh_tree, hf_lcp_message, tvb, offset + 4,
length - 4, ENC_ASCII|ENC_NA);
}
}
break;
case TIMEREMAIN: /* LCP only: RFC 1570 */
if (tree) {
guint32 secs_remaining;
proto_tree_add_item(fh_tree, hf_lcp_magic_number, tvb, offset, 4,
ENC_BIG_ENDIAN);
secs_remaining = tvb_get_ntohl(tvb, offset + 4);
@ -4741,7 +4729,6 @@ dissect_cp(tvbuff_t *tvb, int proto_id, int proto_subtree_index,
proto_tree_add_item(fh_tree, hf_lcp_message, tvb, offset + 8,
length - 8, ENC_ASCII|ENC_NA);
}
}
break;
case TERMREQ:
@ -4749,7 +4736,7 @@ dissect_cp(tvbuff_t *tvb, int proto_id, int proto_subtree_index,
case RESETREQ: /* RESETREQ and RESETACK are CCP only: RFC 1962 */
case RESETACK:
default:
if (tree && (length > 0)) {
if (length > 0) {
proto_tree_add_item(fh_tree, hf_ppp_data, tvb, offset, length,
ENC_NA);
}
@ -4769,8 +4756,7 @@ dissect_ppp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
tvbuff_t *next_tvb;
/* Make direction information filterable */
if (tree &&
(pinfo->p2p_dir == P2P_DIR_RECV || pinfo->p2p_dir == P2P_DIR_SENT)) {
if (pinfo->p2p_dir == P2P_DIR_RECV || pinfo->p2p_dir == P2P_DIR_SENT) {
proto_item *direction_ti = proto_tree_add_uint(tree, hf_ppp_direction,
tvb, 0, 0, pinfo->p2p_dir);
PROTO_ITEM_SET_GENERATED(direction_ti);
@ -4791,13 +4777,10 @@ dissect_ppp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
preceding the protocol type, e.g. an HDLC header; add the length
of the protocol type field to it, and set the length of that item
to the result. */
if (ti != NULL)
proto_item_set_len(ti, proto_offset + proto_len);
if (tree) {
proto_tree_add_uint(fh_tree, hf_ppp_protocol, tvb, 0, proto_len,
ppp_prot);
}
next_tvb = tvb_new_subset_remaining(tvb, proto_len);
@ -4833,7 +4816,7 @@ static int
dissect_vsncp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
proto_item *ti;
proto_tree *fh_tree = NULL;
proto_tree *fh_tree;
proto_tree *field_tree;
guint8 code;
int length, offset;
@ -4845,7 +4828,6 @@ dissect_vsncp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U
col_set_str(pinfo->cinfo, COL_INFO,
val_to_str_const(code, cp_vals, "Unknown"));
if (tree) {
ti = proto_tree_add_item(tree, proto_vsncp, tvb, 0, length, ENC_NA);
fh_tree = proto_item_add_subtree(ti, ett_vsncp);
proto_tree_add_item(fh_tree, hf_vsncp_code, tvb, 0, 1, ENC_BIG_ENDIAN);
@ -4853,7 +4835,6 @@ dissect_vsncp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U
proto_tree_add_item(fh_tree, hf_vsncp_length, tvb, 2, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(fh_tree, hf_ppp_oui, tvb, 4, 3, ENC_BIG_ENDIAN);
}
offset = 7;
length -= 7;
@ -4882,19 +4863,17 @@ dissect_vsncp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U
static int
dissect_vsnp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
proto_item *vsnp_item = NULL;
proto_tree *vsnp_tree = NULL;
proto_item *vsnp_item;
proto_tree *vsnp_tree;
guint32 offset = 0;
tvbuff_t *next_tvb;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "VSNP");
if (tree) {
vsnp_item = proto_tree_add_item(tree, proto_vsnp, tvb, 0, -1, ENC_NA);
vsnp_tree = proto_item_add_subtree(vsnp_item, ett_vsnp);
proto_tree_add_item(vsnp_tree, hf_vsnp_pdnid, tvb, offset, 1,
ENC_BIG_ENDIAN);
}
next_tvb = tvb_new_subset_remaining(tvb, 1);
if (!dissector_try_uint(ppp_subdissector_table, PPP_IP, next_tvb, pinfo,
@ -5104,7 +5083,7 @@ static int
dissect_bap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
proto_item *ti;
proto_tree *fh_tree = NULL;
proto_tree *fh_tree;
proto_tree *field_tree;
guint8 type;
int length, offset;
@ -5116,13 +5095,12 @@ dissect_bap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
col_set_str(pinfo->cinfo, COL_INFO,
val_to_str_const(type, bap_vals, "Unknown"));
if (tree) {
ti = proto_tree_add_item(tree, proto_bap, tvb, 0, length, ENC_NA);
fh_tree = proto_item_add_subtree(ti, ett_bap_options);
proto_tree_add_item(fh_tree, hf_bap_type, tvb, 0, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(fh_tree, hf_bap_identifier, tvb, 1, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(fh_tree, hf_bap_length, tvb, 2, 2, ENC_BIG_ENDIAN);
}
offset = 4;
length -= 4;
@ -5151,10 +5129,9 @@ dissect_comp_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* dat
col_set_str(pinfo->cinfo, COL_PROTOCOL, "PPP Comp");
col_set_str(pinfo->cinfo, COL_INFO, "Compressed data");
if (tree) {
ti = proto_tree_add_item(tree, proto_comp_data, tvb, 0, -1, ENC_NA);
comp_data_tree = proto_item_add_subtree(ti, ett_comp_data);
}
return tvb_captured_length(tvb);
}
#else
@ -5315,8 +5292,8 @@ static const crumb_spec_t iphc_crtp_cntcp_cid16_crumbs[] = {
static int
dissect_iphc_crtp_fh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
proto_tree *fh_tree = NULL, *info_tree;
proto_item *ti = NULL;
proto_tree *fh_tree, *info_tree;
proto_item *ti;
guint ip_hdr_len, flags, seq;
guint length;
guint hdr_len;
@ -5337,7 +5314,6 @@ dissect_iphc_crtp_fh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void*
flags = (tvb_get_guint8(tvb, 2) & IPHC_CRTP_FH_FLAG_MASK);
next_protocol = tvb_get_guint8(tvb, 9);
if (tree) {
ti = proto_tree_add_protocol_format(tree, proto_iphc_crtp, tvb, 0, -1,
"%s", val_to_str_ext_const(PPP_RTP_FH, &ppp_vals_ext, "Unknown"));
fh_tree = proto_item_add_subtree(ti, ett_iphc_crtp);
@ -5348,8 +5324,6 @@ dissect_iphc_crtp_fh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void*
proto_tree_add_item(fh_tree, hf_iphc_crtp_gen, tvb, 2, 1,
ENC_BIG_ENDIAN);
}
/* calculate length of IP header, assume IPv4 */
ip_hdr_len = (tvb_get_guint8(tvb, 0) & 0x0f) * 4;
@ -5569,7 +5543,7 @@ static int
dissect_iphc_crtp_cntcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
proto_tree *cntcp_tree;
proto_item *ti = NULL;
proto_item *ti;
guint length, flags;
guint hdr_length;
int offset = 0;
@ -5581,7 +5555,6 @@ dissect_iphc_crtp_cntcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi
flags = (tvb_get_guint8(tvb, 1) & IPHC_CRTP_FH_FLAG_MASK);
if (tree) {
ti = proto_tree_add_protocol_format(tree, proto_iphc_crtp, tvb, 0, -1,
"%s",
val_to_str_ext_const(PPP_RTP_CNTCP, &ppp_vals_ext, "Unknown"));
@ -5647,7 +5620,6 @@ dissect_iphc_crtp_cntcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi
length -= 2;
proto_tree_add_item(cntcp_tree, hf_iphc_crtp_data, tvb, offset, length, ENC_NA);
}
return tvb_captured_length(tvb);
}
@ -6325,12 +6297,10 @@ dissect_chap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
/* Success or Failure data */
case CHAP_SUCC:
case CHAP_FAIL:
if (tree) {
if (length > 0) {
proto_tree_add_item(fh_tree, hf_chap_message, tvb, offset,
length, ENC_ASCII|ENC_NA);
}
}
/* Show message in info column */
col_append_fstr(pinfo->cinfo, COL_INFO, " (MESSAGE='%s')",