X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/e46e896eabc8311b313acaad472ddbc2183cba74..ec799d60f6cd3f41041b57efe3963c28dda94d4a:/smbutil.c diff --git a/smbutil.c b/smbutil.c index 7d157b66..5eadb4fd 100644 --- a/smbutil.c +++ b/smbutil.c @@ -12,7 +12,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.33 2004-12-29 03:10:25 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.39 2007-07-15 19:07:39 guy Exp $"; #endif #include @@ -107,8 +107,6 @@ interpret_long_date(const u_char *p) double d; time_t ret; - TCHECK2(p[4], 4); - /* this gives us seconds since jan 1st 1601 (approx) */ d = (EXTRACT_LE_32BITS(p + 4) * 256.0 + p[3]) * (1.0e-7 * (1 << 24)); @@ -124,8 +122,6 @@ interpret_long_date(const u_char *p) ret = (time_t)d; return(ret); -trunc: - return(0); } /* @@ -187,7 +183,12 @@ name_ptr(const u_char *buf, int ofs, const u_char *maxbuf) /* XXX - this should use the same code that the DNS dissector does */ if ((c & 0xC0) == 0xC0) { - u_int16_t l = EXTRACT_16BITS(buf + ofs) & 0x3FFF; + u_int16_t l; + + TCHECK2(*p, 2); + if ((p + 1) >= maxbuf) + return(NULL); /* name goes past the end of the buffer */ + l = EXTRACT_16BITS(p) & 0x3FFF; if (l == 0) { /* We have a pointer that points to itself. */ return(NULL); @@ -196,9 +197,8 @@ name_ptr(const u_char *buf, int ofs, const u_char *maxbuf) if (p >= maxbuf) return(NULL); /* name goes past the end of the buffer */ TCHECK2(*p, 1); - return(buf + l); - } else - return(buf + ofs); + } + return(p); trunc: return(NULL); /* name goes past the end of the buffer */ @@ -279,6 +279,7 @@ print_data(const unsigned char *buf, int len) return; printf("[%03X] ", i); for (i = 0; i < len; /*nothing*/) { + TCHECK(buf[i]); printf("%02X ", buf[i] & 0xff); i++; if (i%8 == 0) @@ -310,6 +311,11 @@ print_data(const unsigned char *buf, int len) print_asc(&buf[i - n], n); printf("\n"); } + return; + +trunc: + printf("\n"); + printf("WARNING: Short packet. Try increasing the snap length\n"); } @@ -342,8 +348,10 @@ unistr(const u_char *s, u_int32_t *len, int use_unicode) /* * Skip padding that puts the string on an even boundary. */ - if (((s - startbuf) % 2) != 0) + if (((s - startbuf) % 2) != 0) { + TCHECK(s[0]); s++; + } } if (*len == 0) { /* @@ -353,6 +361,7 @@ unistr(const u_char *s, u_int32_t *len, int use_unicode) sp = s; if (!use_unicode) { for (;;) { + TCHECK(sp[0]); *len += 1; if (sp[0] == 0) break; @@ -361,6 +370,7 @@ unistr(const u_char *s, u_int32_t *len, int use_unicode) strsize = *len - 1; } else { for (;;) { + TCHECK2(sp[0], 2); *len += 2; if (sp[0] == 0 && sp[1] == 0) break; @@ -376,6 +386,7 @@ unistr(const u_char *s, u_int32_t *len, int use_unicode) } if (!use_unicode) { while (strsize != 0) { + TCHECK(s[0]); if (l >= MAX_UNISTR_SIZE) break; if (isprint(s[0])) @@ -391,6 +402,7 @@ unistr(const u_char *s, u_int32_t *len, int use_unicode) } } else { while (strsize != 0) { + TCHECK2(s[0], 2); if (l >= MAX_UNISTR_SIZE) break; if (s[1] == 0 && isprint(s[0])) { @@ -411,6 +423,9 @@ unistr(const u_char *s, u_int32_t *len, int use_unicode) } buf[l] = 0; return buf; + +trunc: + return NULL; } static const u_char * @@ -419,17 +434,18 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf, { int reverse = 0; const char *attrib_fmt = "READONLY|HIDDEN|SYSTEM|VOLUME|DIR|ARCHIVE|"; - int len; while (*fmt && buf