]> The Tcpdump Group git mirrors - tcpdump/blobdiff - smbutil.c
Make 1-element arrays for fields that may repeat.
[tcpdump] / smbutil.c
index 54f3227b10108ddad075113e62562226c09fa0cf..253721dbe605dab49b467246ccf3ba71a0ba3fef 100644 (file)
--- a/smbutil.c
+++ b/smbutil.c
@@ -103,7 +103,7 @@ interpret_long_date(const u_char *p)
     time_t ret;
 
     /* this gives us seconds since jan 1st 1601 (approx) */
-    d = (EXTRACT_LE_U_4(p + 4) * 256.0 + p[3]) * (1.0e-7 * (1 << 24));
+    d = (EXTRACT_LE_U_4(p + 4) * 256.0 + EXTRACT_U_1(p + 3)) * (1.0e-7 * (1 << 24));
 
     /* now adjust by 369 years to make the secs since 1970 */
     d -= 369.0 * 365.25 * 24 * 60 * 60;
@@ -150,7 +150,7 @@ name_interpret(netdissect_options *ndo,
            *out = 0;
            return(0);
        }
-       *out = ((in[0] - 'A') << 4) + (in[1] - 'A');
+       *out = ((EXTRACT_U_1(in) - 'A') << 4) + (EXTRACT_U_1(in + 1) - 'A');
        in += 2;
        out++;
     }
@@ -178,7 +178,7 @@ name_ptr(netdissect_options *ndo,
        return(NULL);   /* name goes past the end of the buffer */
     ND_TCHECK_1(p);
 
-    c = *p;
+    c = EXTRACT_U_1(p);
 
     /* XXX - this should use the same code that the DNS dissector does */
     if ((c & 0xC0) == 0xC0) {
@@ -231,7 +231,7 @@ name_len(netdissect_options *ndo,
     if (s >= maxbuf)
        return(-1);     /* name goes past the end of the buffer */
     ND_TCHECK_1(s);
-    c = *s;
+    c = EXTRACT_U_1(s);
     if ((c & 0xC0) == 0xC0)
        return(2);
     while (*s) {
@@ -282,7 +282,7 @@ smb_print_data(netdissect_options *ndo, const unsigned char *buf, int len)
        return;
     ND_PRINT((ndo, "[%03X] ", i));
     for (i = 0; i < len; /*nothing*/) {
-        ND_TCHECK(buf[i]);
+        ND_TCHECK_1(buf + i);
        ND_PRINT((ndo, "%02X ", EXTRACT_U_1(buf + i) & 0xff));
        i++;
        if (i%8 == 0)
@@ -354,7 +354,7 @@ unistr(netdissect_options *ndo,
         * Skip padding that puts the string on an even boundary.
         */
        if (((s - startbuf) % 2) != 0) {
-           ND_TCHECK(s[0]);
+           ND_TCHECK_1(s);
            s++;
        }
     }
@@ -366,7 +366,7 @@ unistr(netdissect_options *ndo,
        sp = s;
        if (!use_unicode) {
            for (;;) {
-               ND_TCHECK(sp[0]);
+               ND_TCHECK_1(sp);
                *len += 1;
                if (EXTRACT_U_1(sp) == 0)
                    break;
@@ -391,11 +391,11 @@ unistr(netdissect_options *ndo,
     }
     if (!use_unicode) {
        while (strsize != 0) {
-          ND_TCHECK(s[0]);
+          ND_TCHECK_1(s);
            if (l >= MAX_UNISTR_SIZE)
                break;
            if (ND_ISPRINT(EXTRACT_U_1(s)))
-               buf[l] = s[0];
+               buf[l] = EXTRACT_U_1(s);
            else {
                if (EXTRACT_U_1(s) == 0)
                    break;
@@ -412,7 +412,7 @@ unistr(netdissect_options *ndo,
                break;
            if (EXTRACT_U_1(s + 1) == 0 && ND_ISPRINT(EXTRACT_U_1(s))) {
                /* It's a printable ASCII character */
-               buf[l] = s[0];
+               buf[l] = EXTRACT_U_1(s);
            } else {
                /* It's a non-ASCII character or a non-printable ASCII character */
                if (EXTRACT_U_1(s) == 0 && EXTRACT_U_1(s + 1) == 0)
@@ -444,7 +444,7 @@ smb_fdata1(netdissect_options *ndo,
     while (*fmt && buf<maxbuf) {
        switch (*fmt) {
        case 'a':
-           ND_TCHECK(buf[0]);
+           ND_TCHECK_1(buf);
            write_bits(ndo, EXTRACT_U_1(buf), attrib_fmt);
            buf++;
            fmt++;
@@ -472,7 +472,7 @@ smb_fdata1(netdissect_options *ndo,
            strncpy(bitfmt, fmt, l);
            bitfmt[l] = '\0';
            fmt = p + 1;
-           ND_TCHECK(buf[0]);
+           ND_TCHECK_1(buf);
            write_bits(ndo, EXTRACT_U_1(buf), bitfmt);
            buf++;
            break;
@@ -481,7 +481,7 @@ smb_fdata1(netdissect_options *ndo,
        case 'P':
          {
            int l = atoi(fmt + 1);
-           ND_TCHECK2(buf[0], l);
+           ND_TCHECK_LEN(buf, l);
            buf += l;
            fmt++;
            while (isdigit((unsigned char)*fmt))
@@ -495,8 +495,8 @@ smb_fdata1(netdissect_options *ndo,
        case 'b':
          {
            unsigned int x;
-           ND_TCHECK(buf[0]);
-           x = buf[0];
+           ND_TCHECK_1(buf);
+           x = EXTRACT_U_1(buf);
            ND_PRINT((ndo, "%u (0x%x)", x, x));
            buf += 1;
            fmt++;
@@ -554,8 +554,8 @@ smb_fdata1(netdissect_options *ndo,
        case 'B':
          {
            unsigned int x;
-           ND_TCHECK(buf[0]);
-           x = buf[0];
+           ND_TCHECK_1(buf);
+           x = EXTRACT_U_1(buf);
            ND_PRINT((ndo, "0x%X", x));
            buf += 1;
            fmt++;
@@ -589,8 +589,8 @@ smb_fdata1(netdissect_options *ndo,
            switch (*fmt) {
 
            case 'b':
-               ND_TCHECK(buf[0]);
-               stringlen = buf[0];
+               ND_TCHECK_1(buf);
+               stringlen = EXTRACT_U_1(buf);
                ND_PRINT((ndo, "%u", stringlen));
                buf += 1;
                break;
@@ -636,8 +636,8 @@ smb_fdata1(netdissect_options *ndo,
            const char *s;
            uint32_t len;
 
-           ND_TCHECK(*buf);
-           if (*buf != 4 && *buf != 2) {
+           ND_TCHECK_1(buf);
+           if (EXTRACT_U_1(buf) != 4 && EXTRACT_U_1(buf) != 2) {
                ND_PRINT((ndo, "Error! ASCIIZ buffer of type %u", EXTRACT_U_1(buf)));
                return maxbuf;  /* give up */
            }
@@ -653,7 +653,7 @@ smb_fdata1(netdissect_options *ndo,
        case 's':
          {
            int l = atoi(fmt + 1);
-           ND_TCHECK2(*buf, l);
+           ND_TCHECK_LEN(buf, l);
            ND_PRINT((ndo, "%-*.*s", l, l, buf));
            buf += l;
            fmt++;
@@ -663,7 +663,7 @@ smb_fdata1(netdissect_options *ndo,
          }
        case 'c':
          {
-           ND_TCHECK2(*buf, stringlen);
+           ND_TCHECK_LEN(buf, stringlen);
            ND_PRINT((ndo, "%-*.*s", (int)stringlen, (int)stringlen, buf));
            buf += stringlen;
            fmt++;
@@ -685,7 +685,7 @@ smb_fdata1(netdissect_options *ndo,
        case 'h':
          {
            int l = atoi(fmt + 1);
-           ND_TCHECK2(*buf, l);
+           ND_TCHECK_LEN(buf, l);
            while (l--) {
                ND_PRINT((ndo, "%02x", EXTRACT_U_1(buf)));
                buf++;
@@ -716,8 +716,8 @@ smb_fdata1(netdissect_options *ndo,
                    name_type_str(name_type)));
                break;
            case 2:
-               ND_TCHECK(buf[15]);
-               name_type = buf[15];
+               ND_TCHECK_1(buf + 15);
+               name_type = EXTRACT_U_1(buf + 15);
                ND_PRINT((ndo, "%-15.15s NameType=0x%02X (%s)", buf, name_type,
                    name_type_str(name_type)));
                buf += 16;