]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-smb.c
(for 4.9.3) CVE-2018-14880/OSPFv3: Fix a bounds check
[tcpdump] / print-smb.c
index 0147b20d65e71759e474fde9812d4ed34fd4e2c7..944b8d28abfc0c4dc723f477c9e794fcb9f79ac0 100644 (file)
@@ -6,6 +6,8 @@
  * or later
  */
 
+/* \summary: SMB/CIFS printer */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -369,16 +371,21 @@ print_trans(netdissect_options *ndo,
     ND_PRINT((ndo, "smb_bcc=%u\n", bcc));
     if (bcc > 0) {
        smb_fdata(ndo, data1 + 2, f2, maxbuf - (paramlen + datalen), unicodestr);
-
-       if (strcmp((const char *)(data1 + 2), "\\MAILSLOT\\BROWSE") == 0) {
+#define MAILSLOT_BROWSE_STR "\\MAILSLOT\\BROWSE"
+       ND_TCHECK2(*(data1 + 2), strlen(MAILSLOT_BROWSE_STR) + 1);
+       if (strcmp((const char *)(data1 + 2), MAILSLOT_BROWSE_STR) == 0) {
            print_browse(ndo, param, paramlen, data, datalen);
            return;
        }
+#undef MAILSLOT_BROWSE_STR
 
-       if (strcmp((const char *)(data1 + 2), "\\PIPE\\LANMAN") == 0) {
+#define PIPE_LANMAN_STR "\\PIPE\\LANMAN"
+       ND_TCHECK2(*(data1 + 2), strlen(PIPE_LANMAN_STR) + 1);
+       if (strcmp((const char *)(data1 + 2), PIPE_LANMAN_STR) == 0) {
            print_ipc(ndo, param, paramlen, data, datalen);
            return;
        }
+#undef PIPE_LANMAN_STR
 
        if (paramlen)
            smb_fdata(ndo, param, f3, min(param + paramlen, maxbuf), unicodestr);
@@ -804,9 +811,6 @@ print_smb(netdissect_options *ndo,
 
     ND_TCHECK(buf[9]);
     request = (buf[9] & 0x80) ? 0 : 1;
-    flags2 = EXTRACT_LE_16BITS(&buf[10]);
-    unicodestr = flags2 & 0x8000;
-    nterrcodes = flags2 & 0x4000;
     startbuf = buf;
 
     command = buf[4];
@@ -821,6 +825,11 @@ print_smb(netdissect_options *ndo,
     if (ndo->ndo_vflag < 2)
        return;
 
+    ND_TCHECK_16BITS(&buf[10]);
+    flags2 = EXTRACT_LE_16BITS(&buf[10]);
+    unicodestr = flags2 & 0x8000;
+    nterrcodes = flags2 & 0x4000;
+
     /* print out the header */
     smb_fdata(ndo, buf, fmt_smbheader, buf + 33, unicodestr);
 
@@ -936,7 +945,9 @@ nbt_tcp_print(netdissect_options *ndo,
     if (caplen < 4)
        goto trunc;
     maxbuf = data + caplen;
+    ND_TCHECK_8BITS(data);
     type = data[0];
+    ND_TCHECK_16BITS(data + 2);
     nbt_len = EXTRACT_16BITS(data + 2);
     length -= 4;
     caplen -= 4;
@@ -1163,10 +1174,12 @@ nbt_udp137_print(netdissect_options *ndo,
            p = smb_fdata(ndo, p, "Name=[n1]\n#", maxbuf, 0);
            if (p == NULL)
                goto out;
+           ND_TCHECK_16BITS(p);
            restype = EXTRACT_16BITS(p);
            p = smb_fdata(ndo, p, "ResType=[rw]\nResClass=[rw]\nTTL=[rD]\n", p + 8, 0);
            if (p == NULL)
                goto out;
+           ND_TCHECK_16BITS(p);
            rdlen = EXTRACT_16BITS(p);
            ND_PRINT((ndo, "ResourceLength=%d\nResourceData=\n", rdlen));
            p += 2;
@@ -1308,7 +1321,7 @@ out:
 /*
    print netbeui frames
 */
-struct nbf_strings {
+static struct nbf_strings {
        const char      *name;
        const char      *nonverbose;
        const char      *verbose;