]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-smb.c
remove redundant ND_TCHECK, let GET_ routines handle checks
[tcpdump] / print-smb.c
index 402bb71f0c7cd5051d6c0b9103c5e0abb8d2378e..bcd7363dec955c22a7cb42db4ee8bdd2d26f7fb0 100644 (file)
@@ -114,7 +114,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 +138,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 +220,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 +240,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 +308,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 +356,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 +381,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 +398,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 +411,21 @@ 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(maxbuf, words + 1)));
 
-    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(maxbuf, data + 2)));
     }
-    return;
-trunc:
-    nd_print_trunc(ndo);
 }
 
 static void
@@ -450,7 +435,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 +451,21 @@ 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(maxbuf, words + 1)));
 
-    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(maxbuf, data + 2)));
     }
-    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(maxbuf, data + 2)));
     }
-    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,7 @@ 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(maxbuf, data + 2)));
                }
            }
        }
@@ -911,11 +880,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 +895,6 @@ print_smb(netdissect_options *ndo,
        }
        smboffset = newsmboffset;
     }
-
-    return;
-trunc:
-    nd_print_trunc(ndo);
 }
 
 
@@ -952,13 +915,11 @@ nbt_tcp_print(netdissect_options *ndo,
        goto trunc;
     if (ndo->ndo_snapend < data)
        goto trunc;
-    caplen = ndo->ndo_snapend - data;
+    caplen = ND_BYTES_AVAILABLE_AFTER(data);
     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 +1085,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 +1145,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 +1160,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 +1194,7 @@ nbt_udp137_print(netdissect_options *ndo,
                } else {
                    if (p >= maxbuf)
                        goto out;
-                   smb_data_print(ndo, p, min(rdlen, length - (p - data)));
+                   smb_data_print(ndo, p, ND_MIN(rdlen, length - ND_BYTES_BETWEEN(p, data)));
                    p += rdlen;
                }
            }
@@ -1269,7 +1226,7 @@ smb_tcp_print(netdissect_options *ndo,
        goto trunc;
     if (ndo->ndo_snapend < data)
        goto trunc;
-    caplen = ndo->ndo_snapend - data;
+    caplen = ND_BYTES_AVAILABLE_AFTER(data);
     if (caplen < 4)
        goto trunc;
     maxbuf = data + caplen;
@@ -1406,7 +1363,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 +1439,6 @@ netbeui_print(netdissect_options *ndo,
 
 out:
     return;
-trunc:
-    nd_print_trunc(ndo);
 }