Use more the ND_TCHECK_1() macro

This commit is contained in:
Francois-Xavier Le Bail 2017-12-04 20:21:48 +01:00
parent 00b189d27c
commit 451ac4c753
24 changed files with 60 additions and 59 deletions

View File

@ -482,7 +482,7 @@ aodv_print(netdissect_options *ndo,
* The message type is the first byte; make sure we have it
* and then fetch it.
*/
ND_TCHECK(*dat);
ND_TCHECK_1(dat);
msg_type = *dat;
ND_PRINT((ndo, " aodv"));

View File

@ -460,7 +460,7 @@ oam_print (netdissect_options *ndo,
} oam_ptr;
ND_TCHECK(*(p+ATM_HDR_LEN_NOHEC+hec));
ND_TCHECK_1(p + ATM_HDR_LEN_NOHEC + hec);
cell_header = EXTRACT_BE_U_4(p + hec);
cell_type = (EXTRACT_U_1((p + ATM_HDR_LEN_NOHEC + hec)) >> 4) & 0x0f;
func_type = EXTRACT_U_1((p + ATM_HDR_LEN_NOHEC + hec)) & 0x0f;

View File

@ -1398,7 +1398,7 @@ bgp_attr_print(netdissect_options *ndo,
if (len != 1)
ND_PRINT((ndo, "invalid len"));
else {
ND_TCHECK(*tptr);
ND_TCHECK_1(tptr);
ND_PRINT((ndo, "%s", tok2str(bgp_origin_values,
"Unknown Origin Typecode",
EXTRACT_U_1(tptr))));

View File

@ -535,10 +535,10 @@ static int dccp_print_option(netdissect_options *ndo, const u_char *option, u_in
{
uint8_t optlen, i;
ND_TCHECK(*option);
ND_TCHECK_1(option);
if (*option >= 32) {
ND_TCHECK(*(option+1));
ND_TCHECK_1(option + 1);
optlen = EXTRACT_U_1(option + 1);
if (optlen < 2) {
if (*option >= 128)

View File

@ -104,16 +104,16 @@ blabel_print(netdissect_options *ndo,
/* print the bit string as a hex string */
ND_PRINT((ndo, "\\[x"));
for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) {
ND_TCHECK(*bitp);
ND_TCHECK_1(bitp);
ND_PRINT((ndo, "%02x", EXTRACT_U_1(bitp)));
}
if (b > 4) {
ND_TCHECK(*bitp);
ND_TCHECK_1(bitp);
tc = EXTRACT_U_1(bitp);
bitp++;
ND_PRINT((ndo, "%02x", tc & (0xff << (8 - b))));
} else if (b > 0) {
ND_TCHECK(*bitp);
ND_TCHECK_1(bitp);
tc = EXTRACT_U_1(bitp);
bitp++;
ND_PRINT((ndo, "%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b))));

View File

@ -801,7 +801,7 @@ pkeyitlv_print(netdissect_options *ndo,
uint16_t type, tll;
u_int invtlv;
ND_TCHECK(*tdp);
ND_TCHECK_1(tdp);
id = EXTRACT_BE_U_4(tdp);
ND_PRINT((ndo, "%sKeyinfo: Key 0x%x\n", ib, id));
ND_TCHECK(*kdtlv);

View File

@ -106,7 +106,7 @@ ip_finddst(netdissect_options *ndo,
for (; length > 0; cp += len, length -= len) {
int tt;
ND_TCHECK(*cp);
ND_TCHECK_1(cp);
tt = *cp;
if (tt == IPOPT_EOL)
break;
@ -254,7 +254,7 @@ ip_optprint(netdissect_options *ndo,
ND_PRINT((ndo, "%s", sep));
sep = ",";
ND_TCHECK(*cp);
ND_TCHECK_1(cp);
option_code = *cp;
ND_PRINT((ndo, "%s",
@ -706,7 +706,7 @@ ipN_print(netdissect_options *ndo, register const u_char *bp, register u_int len
return;
}
ND_TCHECK(*bp);
ND_TCHECK_1(bp);
switch (*bp & 0xF0) {
case 0x40:
ip_print (ndo, bp, length);

View File

@ -329,7 +329,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
nh = EXTRACT_U_1(cp);
return;
case IPPROTO_ROUTING:
ND_TCHECK(*cp);
ND_TCHECK_1(cp);
advance = rt6_print(ndo, cp, (const u_char *)ip6);
if (advance < 0)
return;

View File

@ -816,7 +816,7 @@ clnp_print(netdissect_options *ndo,
ND_PRINT((ndo, "li < size of fixed part of CLNP header and addresses"));
return (0);
}
ND_TCHECK(*pptr);
ND_TCHECK_1(pptr);
dest_address_length = EXTRACT_U_1(pptr);
pptr += 1;
li -= 1;
@ -833,7 +833,7 @@ clnp_print(netdissect_options *ndo,
ND_PRINT((ndo, "li < size of fixed part of CLNP header and addresses"));
return (0);
}
ND_TCHECK(*pptr);
ND_TCHECK_1(pptr);
source_address_length = EXTRACT_U_1(pptr);
pptr += 1;
li -= 1;
@ -1040,7 +1040,7 @@ clnp_print(netdissect_options *ndo,
case CLNP_PDU_ER: /* fall through */
case CLNP_PDU_ERP:
ND_TCHECK(*pptr);
ND_TCHECK_1(pptr);
if (EXTRACT_U_1(pptr) == NLPID_CLNP) {
ND_PRINT((ndo, "\n\t-----original packet-----\n\t"));
/* FIXME recursion protection */
@ -1174,7 +1174,7 @@ esis_print(netdissect_options *ndo,
const uint8_t *dst, *snpa, *neta;
u_int dstl, snpal, netal;
ND_TCHECK(*pptr);
ND_TCHECK_1(pptr);
if (li < 1) {
ND_PRINT((ndo, ", bad redirect/li"));
return;
@ -1192,7 +1192,7 @@ esis_print(netdissect_options *ndo,
li -= dstl;
ND_PRINT((ndo, "\n\t %s", isonsap_string(ndo, dst, dstl)));
ND_TCHECK(*pptr);
ND_TCHECK_1(pptr);
if (li < 1) {
ND_PRINT((ndo, ", bad redirect/li"));
return;
@ -1208,7 +1208,7 @@ esis_print(netdissect_options *ndo,
snpa = pptr;
pptr += snpal;
li -= snpal;
ND_TCHECK(*pptr);
ND_TCHECK_1(pptr);
if (li < 1) {
ND_PRINT((ndo, ", bad redirect/li"));
return;
@ -1240,7 +1240,7 @@ esis_print(netdissect_options *ndo,
}
case ESIS_PDU_ESH:
ND_TCHECK(*pptr);
ND_TCHECK_1(pptr);
if (li < 1) {
ND_PRINT((ndo, ", bad esh/li"));
return;
@ -1252,7 +1252,7 @@ esis_print(netdissect_options *ndo,
ND_PRINT((ndo, "\n\t Number of Source Addresses: %u", source_address_number));
while (source_address_number > 0) {
ND_TCHECK(*pptr);
ND_TCHECK_1(pptr);
if (li < 1) {
ND_PRINT((ndo, ", bad esh/li"));
return;
@ -1277,7 +1277,7 @@ esis_print(netdissect_options *ndo,
break;
case ESIS_PDU_ISH: {
ND_TCHECK(*pptr);
ND_TCHECK_1(pptr);
if (li < 1) {
ND_PRINT((ndo, ", bad ish/li"));
return;

View File

@ -193,7 +193,7 @@ krb4_print(netdissect_options *ndo,
if ((cp = krb4_print_hdr(ndo, cp)) == NULL)
return;
cp += 4; /* ctime */
ND_TCHECK(*cp);
ND_TCHECK_1(cp);
ND_PRINT((ndo, " %dmin ", EXTRACT_U_1(cp) * 5));
cp++;
PRINT;
@ -203,14 +203,14 @@ krb4_print(netdissect_options *ndo,
case AUTH_MSG_APPL_REQUEST:
cp += 2;
ND_TCHECK(*cp);
ND_TCHECK_1(cp);
ND_PRINT((ndo, "v%d ", EXTRACT_U_1(cp)));
cp++;
PRINT;
ND_TCHECK(*cp);
ND_TCHECK_1(cp);
ND_PRINT((ndo, " (%d)", EXTRACT_U_1(cp)));
cp++;
ND_TCHECK(*cp);
ND_TCHECK_1(cp);
ND_PRINT((ndo, " (%d)", EXTRACT_U_1(cp)));
break;

View File

@ -129,7 +129,7 @@ mpls_print(netdissect_options *ndo, const u_char *bp, u_int length)
* Cisco sends control-plane traffic MPLS-encapsulated in
* this fashion.
*/
ND_TCHECK(*p);
ND_TCHECK_1(p);
if (length < 1) {
/* nothing to print */
return;

View File

@ -59,7 +59,7 @@ msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
ND_PRINT((ndo, " SA"));
else
ND_PRINT((ndo, " SA-Response"));
ND_TCHECK(*sp);
ND_TCHECK_1(sp);
ND_PRINT((ndo, " %u entries", EXTRACT_U_1(sp)));
if ((u_int)((*sp * 12) + 8) < len) {
ND_PRINT((ndo, " [w/data]"));

View File

@ -931,7 +931,7 @@ ospf_decode_lls(netdissect_options *ndo,
ND_PRINT((ndo, ", length: %u", length2));
dptr += 2;
ND_TCHECK(*dptr);
ND_TCHECK_1(dptr);
while (dptr < dataend) {
ND_TCHECK_2(dptr);
lls_type = EXTRACT_BE_U_2(dptr);

View File

@ -49,7 +49,7 @@ otv_print(netdissect_options *ndo, const u_char *bp, u_int len)
if (len < OTV_HDR_LEN)
goto trunc;
ND_TCHECK(*bp);
ND_TCHECK_1(bp);
flags = *bp;
ND_PRINT((ndo, "flags [%s] (0x%02x), ", flags & 0x08 ? "I" : ".", flags));
bp += 1;
@ -63,7 +63,7 @@ otv_print(netdissect_options *ndo, const u_char *bp, u_int len)
bp += 3;
/* Reserved */
ND_TCHECK(*bp);
ND_TCHECK_1(bp);
bp += 1;
ether_print(ndo, bp, len - OTV_HDR_LEN, ndo->ndo_snapend - bp, NULL, NULL);

View File

@ -247,7 +247,7 @@ resp_parse(netdissect_options *ndo, register const u_char *bp, int length)
int ret_len;
LCHECK2(length, 1);
ND_TCHECK(*bp);
ND_TCHECK_1(bp);
op = *bp;
/* bp now points to the op, so these routines must skip it */
@ -464,7 +464,7 @@ resp_get_length(netdissect_options *ndo, register const u_char *bp, int len, con
if (len == 0)
goto trunc;
ND_TCHECK(*bp);
ND_TCHECK_1(bp);
too_large = 0;
neg = 0;
if (*bp == '-') {
@ -478,7 +478,7 @@ resp_get_length(netdissect_options *ndo, register const u_char *bp, int len, con
for (;;) {
if (len == 0)
goto trunc;
ND_TCHECK(*bp);
ND_TCHECK_1(bp);
c = *bp;
if (!(c >= '0' && c <= '9')) {
if (!saw_digit) {
@ -516,7 +516,7 @@ resp_get_length(netdissect_options *ndo, register const u_char *bp, int len, con
len--;
if (len == 0)
goto trunc;
ND_TCHECK(*bp);
ND_TCHECK_1(bp);
if (*bp != '\n') {
bp++;
goto invalid;

View File

@ -97,9 +97,9 @@ rrcp_print(netdissect_options *ndo,
uint8_t rrcp_proto;
uint8_t rrcp_opcode;
ND_TCHECK(*(cp + RRCP_PROTO_OFFSET));
ND_TCHECK_1(cp + RRCP_PROTO_OFFSET);
rrcp_proto = EXTRACT_U_1(cp + RRCP_PROTO_OFFSET);
ND_TCHECK(*(cp + RRCP_OPCODE_ISREPLY_OFFSET));
ND_TCHECK_1(cp + RRCP_OPCODE_ISREPLY_OFFSET);
rrcp_opcode = EXTRACT_U_1((cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_OPCODE_MASK;
if (src != NULL && dst != NULL) {
ND_PRINT((ndo, "%s > %s, ",

View File

@ -250,7 +250,7 @@ slow_print(netdissect_options *ndo,
if (len < 1)
goto tooshort;
ND_TCHECK(*pptr);
ND_TCHECK_1(pptr);
subtype = *pptr;
/*
@ -260,7 +260,7 @@ slow_print(netdissect_options *ndo,
case SLOW_PROTO_LACP:
if (len < 2)
goto tooshort;
ND_TCHECK(*(pptr+1));
ND_TCHECK_1(pptr + 1);
if (*(pptr+1) != LACP_VERSION) {
ND_PRINT((ndo, "LACP version %u packet not supported", EXTRACT_U_1(pptr + 1)));
return;
@ -271,7 +271,7 @@ slow_print(netdissect_options *ndo,
case SLOW_PROTO_MARKER:
if (len < 2)
goto tooshort;
ND_TCHECK(*(pptr+1));
ND_TCHECK_1(pptr + 1);
if (*(pptr+1) != MARKER_VERSION) {
ND_PRINT((ndo, "MARKER version %u packet not supported", EXTRACT_U_1(pptr + 1)));
return;

View File

@ -1188,7 +1188,7 @@ nbt_udp137_print(netdissect_options *ndo,
if (restype == 0x21) {
int numnames;
ND_TCHECK(*p);
ND_TCHECK_1(p);
numnames = p[0];
p = smb_fdata(ndo, p, "NumNames=[B]\n", p + 1, 0);
if (p == NULL)
@ -1197,7 +1197,7 @@ nbt_udp137_print(netdissect_options *ndo,
p = smb_fdata(ndo, p, "Name=[n2]\t#", maxbuf, 0);
if (p == NULL)
goto out;
ND_TCHECK(*p);
ND_TCHECK_1(p);
if (EXTRACT_U_1(p) & 0x80)
ND_PRINT((ndo, "<GROUP> "));
switch (EXTRACT_U_1(p) & 0x60) {

View File

@ -429,7 +429,7 @@ asn1_parse(netdissect_options *ndo,
ND_PRINT((ndo, "[nothing to parse]"));
return -1;
}
ND_TCHECK(*p);
ND_TCHECK_1(p);
/*
* it would be nice to use a bit field, but you can't depend on them.
@ -464,7 +464,7 @@ asn1_parse(netdissect_options *ndo,
* that won't fit in 32 bits.
*/
id = 0;
ND_TCHECK(*p);
ND_TCHECK_1(p);
while (EXTRACT_U_1(p) & ASN_BIT8) {
if (len < 1) {
ND_PRINT((ndo, "[Xtagfield?]"));
@ -474,13 +474,13 @@ asn1_parse(netdissect_options *ndo,
len--;
hdr++;
p++;
ND_TCHECK(*p);
ND_TCHECK_1(p);
}
if (len < 1) {
ND_PRINT((ndo, "[Xtagfield?]"));
return -1;
}
ND_TCHECK(*p);
ND_TCHECK_1(p);
elem->id = id = (id << 7) | EXTRACT_U_1(p);
--len;
++hdr;
@ -490,7 +490,7 @@ asn1_parse(netdissect_options *ndo,
ND_PRINT((ndo, "[no asnlen]"));
return -1;
}
ND_TCHECK(*p);
ND_TCHECK_1(p);
elem->asnlen = *p;
p++; len--; hdr++;
if (elem->asnlen & ASN_BIT8) {
@ -770,7 +770,7 @@ asn1_print(netdissect_options *ndo,
}
for (; i-- > 0; p++) {
ND_TCHECK(*p);
ND_TCHECK_1(p);
o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8);
if (*p & ASN_LONGLEN)
continue;
@ -922,7 +922,7 @@ smi_decode_oid(netdissect_options *ndo,
unsigned int firstval;
for (*oidlen = 0; i-- > 0; p++) {
ND_TCHECK(*p);
ND_TCHECK_1(p);
o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8);
if (*p & ASN_LONGLEN)
continue;

View File

@ -428,13 +428,13 @@ tcp_print(netdissect_options *ndo,
while (hlen > 0) {
if (ch != '\0')
ND_PRINT((ndo, "%c", ch));
ND_TCHECK(*cp);
ND_TCHECK_1(cp);
opt = EXTRACT_U_1(cp);
cp++;
if (ZEROLENOPT(opt))
len = 1;
else {
ND_TCHECK(*cp);
ND_TCHECK_1(cp);
len = EXTRACT_U_1(cp);
cp++; /* total including type, len */
if (len < 2 || len > hlen)

View File

@ -443,7 +443,7 @@ telnet_parse(netdissect_options *ndo, const u_char *sp, u_int length, int print)
break;
p++;
}
ND_TCHECK(*p);
ND_TCHECK_1(p);
if (*p != IAC)
goto pktend;
@ -515,7 +515,7 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length)
osp = sp;
ND_TCHECK(*sp);
ND_TCHECK_1(sp);
while (length > 0 && EXTRACT_U_1(sp) == IAC) {
/*
* Parse the Telnet command without printing it,
@ -544,7 +544,7 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length)
sp += l;
length -= l;
ND_TCHECK(*sp);
ND_TCHECK_1(sp);
}
if (!first) {
if (ndo->ndo_Xflag && 2 < ndo->ndo_vflag)

View File

@ -139,7 +139,7 @@ tftp_print(netdissect_options *ndo,
/* Print options, if any */
while (length != 0) {
ND_TCHECK(*bp);
ND_TCHECK_1(bp);
if (*bp != '\0')
ND_PRINT((ndo, " "));
ui = fn_printztn(ndo, bp, length, ndo->ndo_snapend);
@ -153,7 +153,7 @@ tftp_print(netdissect_options *ndo,
case OACK:
/* Print options */
while (length != 0) {
ND_TCHECK(*bp);
ND_TCHECK_1(bp);
if (*bp != '\0')
ND_PRINT((ndo, " "));
ui = fn_printztn(ndo, bp, length, ndo->ndo_snapend);

View File

@ -636,7 +636,7 @@ smb_fdata1(netdissect_options *ndo,
const char *s;
uint32_t len;
ND_TCHECK(*buf);
ND_TCHECK_1(buf);
if (*buf != 4 && *buf != 2) {
ND_PRINT((ndo, "Error! ASCIIZ buffer of type %u", EXTRACT_U_1(buf)));
return maxbuf; /* give up */

View File

@ -53,6 +53,7 @@
#include <string.h>
#include "netdissect.h"
#include "extract.h"
#include "ascii_strcasecmp.h"
#include "timeval-operations.h"
@ -759,7 +760,7 @@ print_txt_line(netdissect_options *ndo, const char *protoname,
startidx = idx;
while (idx < len) {
ND_TCHECK(*(pptr+idx));
ND_TCHECK_1(pptr + idx);
if (*(pptr+idx) == '\n') {
/*
* LF without CR; end of line.
@ -775,7 +776,7 @@ print_txt_line(netdissect_options *ndo, const char *protoname,
/* not in this packet */
return (0);
}
ND_TCHECK(*(pptr+idx+1));
ND_TCHECK_1(pptr + idx + 1);
if (*(pptr+idx+1) == '\n') {
/*
* CR-LF; end of line.