X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/6f5ba2b651cd9d4b7fa8ee5c4f94460645877c45..0f328b4aa16b0b47f05a85c440ce1d07719e3cac:/smbutil.c diff --git a/smbutil.c b/smbutil.c index fc9b3cc6..5a292a36 100644 --- a/smbutil.c +++ b/smbutil.c @@ -73,7 +73,7 @@ make_unix_date(const u_char *date_ptr) { uint32_t dos_date = 0; - dos_date = EXTRACT_LE_32BITS(date_ptr); + dos_date = EXTRACT_LE_U_4(date_ptr); return int_unix_date(dos_date); } @@ -87,7 +87,7 @@ make_unix_date2(const u_char *date_ptr) { uint32_t x, x2; - x = EXTRACT_LE_32BITS(date_ptr); + x = EXTRACT_LE_U_4(date_ptr); x2 = ((x & 0xFFFF) << 16) | ((x & 0xFFFF0000) >> 16); return int_unix_date(x2); } @@ -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_32BITS(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; @@ -132,8 +132,9 @@ name_interpret(netdissect_options *ndo, if (in >= maxbuf) return(-1); /* name goes past the end of the buffer */ - ND_TCHECK2(*in, 1); - len = (*in++) / 2; + ND_TCHECK_1(in); + len = EXTRACT_U_1(in) / 2; + in++; *out=0; @@ -141,14 +142,15 @@ name_interpret(netdissect_options *ndo, return(0); while (len--) { - ND_TCHECK2(*in, 2); + ND_TCHECK_2(in); if (in + 1 >= maxbuf) return(-1); /* name goes past the end of the buffer */ - if (in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') { + if (EXTRACT_U_1(in) < 'A' || EXTRACT_U_1(in) > 'P' || + EXTRACT_U_1(in + 1) < 'A' || EXTRACT_U_1(in + 1) > 'P') { *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++; } @@ -174,18 +176,18 @@ name_ptr(netdissect_options *ndo, p = buf + ofs; if (p >= maxbuf) return(NULL); /* name goes past the end of the buffer */ - ND_TCHECK2(*p, 1); + 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) { uint16_t l; - ND_TCHECK2(*p, 2); + ND_TCHECK_2(p); if ((p + 1) >= maxbuf) return(NULL); /* name goes past the end of the buffer */ - l = EXTRACT_16BITS(p) & 0x3FFF; + l = EXTRACT_BE_U_2(p) & 0x3FFF; if (l == 0) { /* We have a pointer that points to itself. */ return(NULL); @@ -193,7 +195,7 @@ name_ptr(netdissect_options *ndo, p = buf + l; if (p >= maxbuf) return(NULL); /* name goes past the end of the buffer */ - ND_TCHECK2(*p, 1); + ND_TCHECK_1(p); } return(p); @@ -228,16 +230,16 @@ name_len(netdissect_options *ndo, if (s >= maxbuf) return(-1); /* name goes past the end of the buffer */ - ND_TCHECK2(*s, 1); - c = *s; + ND_TCHECK_1(s); + c = EXTRACT_U_1(s); if ((c & 0xC0) == 0xC0) return(2); while (*s) { if (s >= maxbuf) return(-1); /* name goes past the end of the buffer */ - ND_TCHECK2(*s, 1); + ND_TCHECK_1(s); s += (*s) + 1; - ND_TCHECK2(*s, 1); + ND_TCHECK_1(s); } return(PTR_DIFF(s, s0) + 1); @@ -251,7 +253,7 @@ print_asc(netdissect_options *ndo, { int i; for (i = 0; i < len; i++) - safeputchar(ndo, buf[i]); + safeputchar(ndo, EXTRACT_U_1(buf + i)); } static const char * @@ -280,15 +282,15 @@ 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_PRINT((ndo, "%02X ", buf[i] & 0xff)); + ND_TCHECK_1(buf + i); + ND_PRINT((ndo, "%02X ", EXTRACT_U_1(buf + i) & 0xff)); i++; if (i%8 == 0) ND_PRINT((ndo, " ")); if (i % 16 == 0) { - print_asc(ndo, &buf[i - 16], 8); + print_asc(ndo, buf + i - 16, 8); ND_PRINT((ndo, " ")); - print_asc(ndo, &buf[i - 8], 8); + print_asc(ndo, buf + i - 8, 8); ND_PRINT((ndo, "\n")); if (i < len) ND_PRINT((ndo, "[%03X] ", i)); @@ -305,11 +307,11 @@ smb_print_data(netdissect_options *ndo, const unsigned char *buf, int len) ND_PRINT((ndo, " ")); n = min(8, i % 16); - print_asc(ndo, &buf[i - (i % 16)], n); + print_asc(ndo, buf + i - (i % 16), n); ND_PRINT((ndo, " ")); n = (i % 16) - n; if (n > 0) - print_asc(ndo, &buf[i - n], n); + print_asc(ndo, buf + i - n, n); ND_PRINT((ndo, "\n")); } return; @@ -352,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++; } } @@ -364,18 +366,18 @@ unistr(netdissect_options *ndo, sp = s; if (!use_unicode) { for (;;) { - ND_TCHECK(sp[0]); + ND_TCHECK_1(sp); *len += 1; - if (sp[0] == 0) + if (EXTRACT_U_1(sp) == 0) break; sp++; } strsize = *len - 1; } else { for (;;) { - ND_TCHECK2(sp[0], 2); + ND_TCHECK_2(sp); *len += 2; - if (sp[0] == 0 && sp[1] == 0) + if (EXTRACT_U_1(sp) == 0 && EXTRACT_U_1(sp + 1) == 0) break; sp += 2; } @@ -389,13 +391,13 @@ 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(s[0])) - buf[l] = s[0]; + if (ND_ISPRINT(EXTRACT_U_1(s))) + buf[l] = EXTRACT_U_1(s); else { - if (s[0] == 0) + if (EXTRACT_U_1(s) == 0) break; buf[l] = '.'; } @@ -405,15 +407,15 @@ unistr(netdissect_options *ndo, } } else { while (strsize != 0) { - ND_TCHECK2(s[0], 2); + ND_TCHECK_2(s); if (l >= MAX_UNISTR_SIZE) break; - if (s[1] == 0 && ND_ISPRINT(s[0])) { + 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 (s[0] == 0 && s[1] == 0) + if (EXTRACT_U_1(s) == 0 && EXTRACT_U_1(s + 1) == 0) break; buf[l] = '.'; } @@ -442,15 +444,15 @@ smb_fdata1(netdissect_options *ndo, while (*fmt && buf