X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/de1bfbceb3bdb9110265fba8b540905dc7918aea..refs/heads/master:/print-smb.c diff --git a/print-smb.c b/print-smb.c index 77d9f814..46dd2ef3 100644 --- a/print-smb.c +++ b/print-smb.c @@ -8,9 +8,7 @@ /* \summary: SMB/CIFS printer */ -#ifdef HAVE_CONFIG_H #include -#endif #include "netdissect-stdinc.h" @@ -114,7 +112,6 @@ trans2_qfsinfo(netdissect_options *ndo, const char *fmt=""; if (request) { - ND_TCHECK_2(param); level = GET_LE_U_2(param); fmt = "InfoLevel=[u]\n"; smb_fdata(ndo, param, fmt, param + pcnt, unicodestr); @@ -139,9 +136,6 @@ trans2_qfsinfo(netdissect_options *ndo, ND_PRINT("data:\n"); smb_data_print(ndo, data, dcnt); } - return; -trunc: - nd_print_trunc(ndo); } static const struct smbfnsint trans2_fns[] = { @@ -224,7 +218,6 @@ print_trans2(netdissect_options *ndo, f2 = fn->descript.rep_f2; } - ND_TCHECK_2(dat); bcc = GET_LE_U_2(dat); ND_PRINT("smb_bcc=%u\n", bcc); if (fn->descript.fn) @@ -245,7 +238,6 @@ print_browse(netdissect_options *ndo, const u_char *maxbuf = data + datalen; u_int command; - ND_TCHECK_1(data); command = GET_U_1(data); smb_fdata(ndo, param, "BROWSE PACKET\n|Param ", param+paramlen, unicodestr); @@ -314,9 +306,6 @@ print_browse(netdissect_options *ndo, data = smb_fdata(ndo, data, "Unknown Browser Frame ", maxbuf, unicodestr); break; } - return; -trunc: - nd_print_trunc(ndo); } @@ -365,10 +354,9 @@ print_trans(netdissect_options *ndo, } smb_fdata(ndo, words + 1, f1, - min(words + 1 + 2 * GET_U_1(words), maxbuf), + ND_MIN(words + 1 + 2 * GET_U_1(words), maxbuf), unicodestr); - ND_TCHECK_2(data1); bcc = GET_LE_U_2(data1); ND_PRINT("smb_bcc=%u\n", bcc); if (bcc > 0) { @@ -391,9 +379,9 @@ print_trans(netdissect_options *ndo, #undef PIPE_LANMAN_STR if (paramlen) - smb_fdata(ndo, param, f3, min(param + paramlen, maxbuf), unicodestr); + smb_fdata(ndo, param, f3, ND_MIN(param + paramlen, maxbuf), unicodestr); if (datalen) - smb_fdata(ndo, data, f4, min(data + datalen, maxbuf), unicodestr); + smb_fdata(ndo, data, f4, ND_MIN(data + datalen, maxbuf), unicodestr); } return; trunc: @@ -408,7 +396,6 @@ print_negprot(netdissect_options *ndo, u_int wct, bcc; const char *f1 = NULL, *f2 = NULL; - ND_TCHECK_1(words); wct = GET_U_1(words); if (request) f2 = "*|Dialect=[Y]\n"; @@ -422,25 +409,22 @@ print_negprot(netdissect_options *ndo, } if (f1) - smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf), + smb_fdata(ndo, words + 1, f1, ND_MIN(words + 1 + wct * 2, maxbuf), unicodestr); else - smb_data_print(ndo, words + 1, min(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1))); + smb_data_print(ndo, words + 1, + ND_MIN(wct * 2, ND_BYTES_BETWEEN(words + 1, maxbuf))); - ND_TCHECK_2(data); bcc = GET_LE_U_2(data); ND_PRINT("smb_bcc=%u\n", bcc); if (bcc > 0) { if (f2) - smb_fdata(ndo, data + 2, f2, min(data + 2 + GET_LE_U_2(data), + smb_fdata(ndo, data + 2, f2, ND_MIN(data + 2 + GET_LE_U_2(data), maxbuf), unicodestr); else smb_data_print(ndo, data + 2, - min(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2))); + ND_MIN(GET_LE_U_2(data), ND_BYTES_BETWEEN(data + 2, maxbuf))); } - return; -trunc: - nd_print_trunc(ndo); } static void @@ -450,7 +434,6 @@ print_sesssetup(netdissect_options *ndo, u_int wct, bcc; const char *f1 = NULL, *f2 = NULL; - ND_TCHECK_1(words); wct = GET_U_1(words); if (request) { if (wct == 10) @@ -467,25 +450,22 @@ print_sesssetup(netdissect_options *ndo, } if (f1) - smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf), + smb_fdata(ndo, words + 1, f1, ND_MIN(words + 1 + wct * 2, maxbuf), unicodestr); else - smb_data_print(ndo, words + 1, min(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1))); + smb_data_print(ndo, words + 1, + ND_MIN(wct * 2, ND_BYTES_BETWEEN(words + 1, maxbuf))); - ND_TCHECK_2(data); bcc = GET_LE_U_2(data); ND_PRINT("smb_bcc=%u\n", bcc); if (bcc > 0) { if (f2) - smb_fdata(ndo, data + 2, f2, min(data + 2 + GET_LE_U_2(data), + smb_fdata(ndo, data + 2, f2, ND_MIN(data + 2 + GET_LE_U_2(data), maxbuf), unicodestr); else smb_data_print(ndo, data + 2, - min(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2))); + ND_MIN(GET_LE_U_2(data), ND_BYTES_BETWEEN(data + 2, maxbuf))); } - return; -trunc: - nd_print_trunc(ndo); } static void @@ -496,11 +476,9 @@ print_lockingandx(netdissect_options *ndo, const u_char *maxwords; const char *f1 = NULL, *f2 = NULL; - ND_TCHECK_1(words); wct = GET_U_1(words); if (request) { f1 = "Com2=[w]\nOff2=[u]\nHandle=[u]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[u]\nLockCount=[u]\n"; - ND_TCHECK_1(words + 7); if (GET_U_1(words + 7) & 0x10) f2 = "*Process=[u]\n[P2]Offset=[M]\nLength=[M]\n"; else @@ -509,24 +487,20 @@ print_lockingandx(netdissect_options *ndo, f1 = "Com2=[w]\nOff2=[u]\n"; } - maxwords = min(words + 1 + wct * 2, maxbuf); + maxwords = ND_MIN(words + 1 + wct * 2, maxbuf); if (wct) smb_fdata(ndo, words + 1, f1, maxwords, unicodestr); - ND_TCHECK_2(data); bcc = GET_LE_U_2(data); ND_PRINT("smb_bcc=%u\n", bcc); if (bcc > 0) { if (f2) - smb_fdata(ndo, data + 2, f2, min(data + 2 + GET_LE_U_2(data), + smb_fdata(ndo, data + 2, f2, ND_MIN(data + 2 + GET_LE_U_2(data), maxbuf), unicodestr); else smb_data_print(ndo, data + 2, - min(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2))); + ND_MIN(GET_LE_U_2(data), ND_BYTES_BETWEEN(data + 2, maxbuf))); } - return; -trunc: - nd_print_trunc(ndo); } @@ -817,7 +791,6 @@ print_smb(netdissect_options *ndo, ndo->ndo_protocol = "smb"; - ND_TCHECK_1(buf + 9); request = (GET_U_1(buf + 9) & 0x80) ? 0 : 1; startbuf = buf; @@ -834,7 +807,6 @@ print_smb(netdissect_options *ndo, return; ND_PRINT("\n"); - ND_TCHECK_2(buf + 10); flags2 = GET_LE_U_2(buf + 10); unicodestr = flags2 & 0x8000; nterrcodes = flags2 & 0x4000; @@ -861,10 +833,9 @@ print_smb(netdissect_options *ndo, u_int newsmboffset; words = buf + smboffset; - ND_TCHECK_1(words); wct = GET_U_1(words); data = words + 1 + wct * 2; - maxwords = min(data, maxbuf); + maxwords = ND_MIN(data, maxbuf); if (request) { f1 = fn->descript.req_f1; @@ -886,14 +857,12 @@ print_smb(netdissect_options *ndo, u_int v; for (i = 0; words + 1 + 2 * i < maxwords; i++) { - ND_TCHECK_2(words + 1 + 2 * i); v = GET_LE_U_2(words + 1 + 2 * i); ND_PRINT("smb_vwv[%u]=%u (0x%X)\n", i, v, v); } } } - ND_TCHECK_2(data); bcc = GET_LE_U_2(data); ND_PRINT("smb_bcc=%u\n", bcc); if (f2) { @@ -902,7 +871,8 @@ print_smb(netdissect_options *ndo, } else { if (bcc > 0) { ND_PRINT("smb_buf[]=\n"); - smb_data_print(ndo, data + 2, min(bcc, ND_BYTES_BETWEEN(maxbuf, data + 2))); + smb_data_print(ndo, data + 2, + ND_MIN(bcc, ND_BYTES_BETWEEN(data + 2, maxbuf))); } } } @@ -911,11 +881,9 @@ print_smb(netdissect_options *ndo, break; if (wct == 0) break; - ND_TCHECK_1(words + 1); command = GET_U_1(words + 1); if (command == 0xFF) break; - ND_TCHECK_2(words + 3); newsmboffset = GET_LE_U_2(words + 3); fn = smbfind(command, smb_fns); @@ -928,10 +896,6 @@ print_smb(netdissect_options *ndo, } smboffset = newsmboffset; } - - return; -trunc: - nd_print_trunc(ndo); } @@ -956,9 +920,7 @@ nbt_tcp_print(netdissect_options *ndo, if (caplen < 4) goto trunc; maxbuf = data + caplen; - ND_TCHECK_1(data); type = GET_U_1(data); - ND_TCHECK_2(data + 2); nbt_len = GET_BE_U_2(data + 2); length -= 4; caplen -= 4; @@ -1124,7 +1086,6 @@ nbt_udp137_print(netdissect_options *ndo, u_int total, i; ndo->ndo_protocol = "nbt_udp137"; - ND_TCHECK_2(data + 10); name_trn_id = GET_BE_U_2(data); response = (GET_U_1(data + 2) >> 7); opcode = (GET_U_1(data + 2) >> 3) & 0xF; @@ -1185,12 +1146,10 @@ nbt_udp137_print(netdissect_options *ndo, p = smb_fdata(ndo, p, "Name=[n1]\n#", maxbuf, 0); if (p == NULL) goto out; - ND_TCHECK_2(p); restype = GET_BE_U_2(p); p = smb_fdata(ndo, p, "ResType=[rw]\nResClass=[rw]\nTTL=[rU]\n", p + 8, 0); if (p == NULL) goto out; - ND_TCHECK_2(p); rdlen = GET_BE_U_2(p); ND_PRINT("ResourceLength=%u\nResourceData=\n", rdlen); p += 2; @@ -1202,7 +1161,6 @@ nbt_udp137_print(netdissect_options *ndo, if (restype == 0x21) { u_int numnames; - ND_TCHECK_1(p); numnames = GET_U_1(p); p = smb_fdata(ndo, p, "NumNames=[B]\n", p + 1, 0); if (p == NULL) @@ -1237,7 +1195,8 @@ nbt_udp137_print(netdissect_options *ndo, } else { if (p >= maxbuf) goto out; - smb_data_print(ndo, p, min(rdlen, length - ND_BYTES_BETWEEN(p, data))); + smb_data_print(ndo, p, + ND_MIN(rdlen, length - ND_BYTES_BETWEEN(data, p))); p += rdlen; } } @@ -1406,7 +1365,6 @@ netbeui_print(netdissect_options *ndo, ndo->ndo_protocol = "netbeui"; if (maxbuf > ndo->ndo_snapend) maxbuf = ndo->ndo_snapend; - ND_TCHECK_1(data + 4); len = GET_LE_U_2(data); command = GET_U_1(data + 4); data2 = data + len; @@ -1483,8 +1441,6 @@ netbeui_print(netdissect_options *ndo, out: return; -trunc: - nd_print_trunc(ndo); }