X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/e83dfd9b161eeb2bde1a42b5e3f2fc83639d54f3..1eae026e557619f80178239dfb79edfd92a31125:/print-smb.c diff --git a/print-smb.c b/print-smb.c index af775370..b3f855bd 100644 --- a/print-smb.c +++ b/print-smb.c @@ -25,6 +25,8 @@ static const char tstr[] = "[|SMB]"; static int request = 0; static int unicodestr = 0; +extern const u_char *startbuf; + const u_char *startbuf = NULL; struct smbdescript { @@ -179,7 +181,7 @@ print_trans2(netdissect_options *ndo, const char *f1 = NULL, *f2 = NULL; int pcnt, dcnt; - ND_TCHECK(words[0]); + ND_TCHECK_1(words); if (request) { ND_TCHECK_2(w + (14 * 2)); pcnt = EXTRACT_LE_U_2(w + 9 * 2); @@ -188,7 +190,7 @@ print_trans2(netdissect_options *ndo, data = buf + EXTRACT_LE_U_2(w + 12 * 2); fn = smbfindint(EXTRACT_LE_U_2(w + 14 * 2), trans2_fns); } else { - if (words[0] == 0) { + if (EXTRACT_U_1(words) == 0) { ND_PRINT((ndo, "%s\n", fn->name)); ND_PRINT((ndo, "Trans2Interim\n")); return; @@ -203,7 +205,7 @@ print_trans2(netdissect_options *ndo, ND_PRINT((ndo, "%s param_length=%d data_length=%d\n", fn->name, pcnt, dcnt)); if (request) { - if (words[0] == 8) { + if (EXTRACT_U_1(words) == 8) { smb_fdata(ndo, words + 1, "Trans2Secondary\nTotParam=[d]\nTotData=[d]\nParamCnt=[d]\nParamOff=[d]\nParamDisp=[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nHandle=[d]\n", maxbuf, unicodestr); @@ -244,8 +246,8 @@ print_browse(netdissect_options *ndo, const u_char *maxbuf = data + datalen; int command; - ND_TCHECK(data[0]); - command = data[0]; + ND_TCHECK_1(data); + command = EXTRACT_U_1(data); smb_fdata(ndo, param, "BROWSE PACKET\n|Param ", param+paramlen, unicodestr); @@ -363,8 +365,9 @@ print_trans(netdissect_options *ndo, f4 = "|Data "; } - smb_fdata(ndo, words + 1, f1, min(words + 1 + 2 * words[0], maxbuf), - unicodestr); + smb_fdata(ndo, words + 1, f1, + min(words + 1 + 2 * EXTRACT_U_1(words), maxbuf), + unicodestr); ND_TCHECK_2(data1); bcc = EXTRACT_LE_U_2(data1); @@ -400,8 +403,8 @@ print_negprot(netdissect_options *ndo, u_int wct, bcc; const char *f1 = NULL, *f2 = NULL; - ND_TCHECK(words[0]); - wct = words[0]; + ND_TCHECK_1(words); + wct = EXTRACT_U_1(words); if (request) f2 = "*|Dialect=[Y]\n"; else { @@ -442,8 +445,8 @@ print_sesssetup(netdissect_options *ndo, u_int wct, bcc; const char *f1 = NULL, *f2 = NULL; - ND_TCHECK(words[0]); - wct = words[0]; + ND_TCHECK_1(words); + wct = EXTRACT_U_1(words); if (request) { if (wct == 10) f1 = "Com2=[w]\nOff2=[d]\nBufSize=[d]\nMpxMax=[d]\nVcNum=[d]\nSessionKey=[W]\nPassLen=[d]\nCryptLen=[d]\nCryptOff=[d]\nPass&Name=\n"; @@ -488,12 +491,12 @@ print_lockingandx(netdissect_options *ndo, const u_char *maxwords; const char *f1 = NULL, *f2 = NULL; - ND_TCHECK(words[0]); - wct = words[0]; + ND_TCHECK_1(words); + wct = EXTRACT_U_1(words); if (request) { f1 = "Com2=[w]\nOff2=[d]\nHandle=[d]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[d]\nLockCount=[d]\n"; - ND_TCHECK(words[7]); - if (words[7] & 0x10) + ND_TCHECK_1(words + 7); + if (EXTRACT_U_1(words + 7) & 0x10) f2 = "*Process=[d]\n[P2]Offset=[M]\nLength=[M]\n"; else f2 = "*Process=[d]\nOffset=[D]\nLength=[D]\n"; @@ -807,11 +810,11 @@ print_smb(netdissect_options *ndo, "[P4]SMB Command = [B]\nError class = [BP1]\nError code = [d]\nFlags1 = [B]\nFlags2 = [B][P13]\nTree ID = [d]\nProc ID = [d]\nUID = [d]\nMID = [d]\nWord Count = [b]\n"; int smboffset; - ND_TCHECK(buf[9]); - request = (buf[9] & 0x80) ? 0 : 1; + ND_TCHECK_1(buf + 9); + request = (EXTRACT_U_1(buf + 9) & 0x80) ? 0 : 1; startbuf = buf; - command = buf[4]; + command = EXTRACT_U_1(buf + 4); fn = smbfind(command, smb_fns); @@ -836,7 +839,7 @@ print_smb(netdissect_options *ndo, if (nterror) ND_PRINT((ndo, "NTError = %s\n", nt_errstr(nterror))); } else { - if (buf[5]) + if (EXTRACT_U_1(buf + 5)) ND_PRINT((ndo, "SMBError = %s\n", smb_errstr(EXTRACT_U_1(buf + 5), EXTRACT_LE_U_2(buf + 7)))); } @@ -850,8 +853,8 @@ print_smb(netdissect_options *ndo, int newsmboffset; words = buf + smboffset; - ND_TCHECK(words[0]); - wct = words[0]; + ND_TCHECK_1(words); + wct = EXTRACT_U_1(words); data = words + 1 + wct * 2; maxwords = min(data, maxbuf); @@ -873,8 +876,8 @@ print_smb(netdissect_options *ndo, int i; int v; - for (i = 0; &words[1 + 2 * i] < maxwords; i++) { - ND_TCHECK_2(words + (1 + 2 * i)); + for (i = 0; words + 1 + 2 * i < maxwords; i++) { + ND_TCHECK_2(words + 1 + 2 * i); v = EXTRACT_LE_U_2(words + 1 + 2 * i); ND_PRINT((ndo, "smb_vwv[%d]=%d (0x%X)\n", i, v, v)); } @@ -899,8 +902,8 @@ print_smb(netdissect_options *ndo, break; if (wct == 0) break; - ND_TCHECK(words[1]); - command = words[1]; + ND_TCHECK_1(words + 1); + command = EXTRACT_U_1(words + 1); if (command == 0xFF) break; ND_TCHECK_2(words + 3); @@ -944,7 +947,9 @@ nbt_tcp_print(netdissect_options *ndo, if (caplen < 4) goto trunc; maxbuf = data + caplen; - type = data[0]; + ND_TCHECK_1(data); + type = EXTRACT_U_1(data); + ND_TCHECK_2(data + 2); nbt_len = EXTRACT_BE_U_2(data + 2); length -= 4; caplen -= 4; @@ -976,7 +981,7 @@ nbt_tcp_print(netdissect_options *ndo, goto trunc; if (caplen < 4) goto trunc; - ecode = data[4]; + ecode = EXTRACT_U_1(data + 4); ND_PRINT((ndo, "Session Reject, ")); switch (ecode) { @@ -1049,7 +1054,7 @@ nbt_tcp_print(netdissect_options *ndo, if (data == NULL) break; if (nbt_len >= 1 && caplen >= 1) { - ecode = origdata[4]; + ecode = EXTRACT_U_1(origdata + 4); switch (ecode) { case 0x80: ND_PRINT((ndo, "Not listening on called name\n")); @@ -1112,10 +1117,10 @@ nbt_udp137_print(netdissect_options *ndo, ND_TCHECK_2(data + 10); name_trn_id = EXTRACT_BE_U_2(data); - response = (data[2] >> 7); - opcode = (data[2] >> 3) & 0xF; - nm_flags = ((data[2] & 0x7) << 4) + (data[3] >> 4); - rcode = data[3] & 0xF; + response = (EXTRACT_U_1(data + 2) >> 7); + opcode = (EXTRACT_U_1(data + 2) >> 3) & 0xF; + nm_flags = ((EXTRACT_U_1(data + 2) & 0x7) << 4) + (EXTRACT_U_1(data + 3) >> 4); + rcode = EXTRACT_U_1(data + 3) & 0xF; qdcount = EXTRACT_BE_U_2(data + 4); ancount = EXTRACT_BE_U_2(data + 6); nscount = EXTRACT_BE_U_2(data + 8); @@ -1188,8 +1193,8 @@ nbt_udp137_print(netdissect_options *ndo, if (restype == 0x21) { int numnames; - ND_TCHECK(*p); - numnames = p[0]; + ND_TCHECK_1(p); + numnames = EXTRACT_U_1(p); p = smb_fdata(ndo, p, "NumNames=[B]\n", p + 1, 0); if (p == NULL) goto out; @@ -1197,22 +1202,22 @@ nbt_udp137_print(netdissect_options *ndo, p = smb_fdata(ndo, p, "Name=[n2]\t#", maxbuf, 0); if (p == NULL) goto out; - ND_TCHECK(*p); - if (p[0] & 0x80) + ND_TCHECK_1(p); + if (EXTRACT_U_1(p) & 0x80) ND_PRINT((ndo, " ")); - switch (p[0] & 0x60) { + switch (EXTRACT_U_1(p) & 0x60) { case 0x00: ND_PRINT((ndo, "B ")); break; case 0x20: ND_PRINT((ndo, "P ")); break; case 0x40: ND_PRINT((ndo, "M ")); break; case 0x60: ND_PRINT((ndo, "_ ")); break; } - if (p[0] & 0x10) + if (EXTRACT_U_1(p) & 0x10) ND_PRINT((ndo, " ")); - if (p[0] & 0x08) + if (EXTRACT_U_1(p) & 0x08) ND_PRINT((ndo, " ")); - if (p[0] & 0x04) + if (EXTRACT_U_1(p) & 0x04) ND_PRINT((ndo, " ")); - if (p[0] & 0x02) + if (EXTRACT_U_1(p) & 0x02) ND_PRINT((ndo, " ")); ND_PRINT((ndo, "\n")); p += 2; @@ -1304,7 +1309,7 @@ nbt_udp138_print(netdissect_options *ndo, if (data != NULL) { /* If there isn't enough data for "\377SMB", don't check for it. */ - if (&data[3] >= maxbuf) + if ((data + 3) >= maxbuf) goto out; if (memcmp(data, "\377SMB",4) == 0) @@ -1385,9 +1390,9 @@ netbeui_print(netdissect_options *ndo, if (maxbuf > ndo->ndo_snapend) maxbuf = ndo->ndo_snapend; - ND_TCHECK(data[4]); + ND_TCHECK_1(data + 4); len = EXTRACT_LE_U_2(data); - command = data[4]; + command = EXTRACT_U_1(data + 4); data2 = data + len; if (data2 >= maxbuf) { data2 = maxbuf; @@ -1442,7 +1447,7 @@ netbeui_print(netdissect_options *ndo, goto out; /* If there isn't enough data for "\377SMB", don't look for it. */ - if (&data2[3] >= maxbuf) + if ((data2 + 3) >= maxbuf) goto out; if (memcmp(data2, "\377SMB",4) == 0) @@ -1450,7 +1455,7 @@ netbeui_print(netdissect_options *ndo, else { int i; for (i = 0; i < 128; i++) { - if (&data2[i + 3] >= maxbuf) + if ((data2 + i + 3) >= maxbuf) break; if (memcmp(data2 + i, "\377SMB", 4) == 0) { ND_PRINT((ndo, "found SMB packet at %d\n", i)); @@ -1488,7 +1493,7 @@ ipx_netbios_print(netdissect_options *ndo, maxbuf = ndo->ndo_snapend; startbuf = data; for (i = 0; i < 128; i++) { - if (&data[i + 4] > maxbuf) + if ((data + i + 4) > maxbuf) break; if (memcmp(data + i, "\377SMB", 4) == 0) { smb_fdata(ndo, data, "\n>>> IPX transport ", data + i, 0);