]> The Tcpdump Group git mirrors - tcpdump/blobdiff - smbutil.c
add tracefiles for infinite loop testing
[tcpdump] / smbutil.c
index af237f1e04c952e7b312748cd15708b2afb60342..418779a9f27c7cbb5b755e7c7035b0407fe814b2 100644 (file)
--- a/smbutil.c
+++ b/smbutil.c
@@ -11,8 +11,8 @@
 #endif
 
 #ifndef lint
-static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.23 2002-08-06 04:42:07 guy Exp $";
+static const char rcsid[] _U_ =
+     "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.26.2.2 2003-11-16 08:51:56 guy Exp $";
 #endif
 
 #include <tcpdump-stdinc.h>
@@ -252,10 +252,10 @@ print_asc(const unsigned char *buf, int len)
        safeputchar(buf[i]);
 }
 
-static char *
+static const char *
 name_type_str(int name_type)
 {
-    char *f = NULL;
+    const char *f = NULL;
 
     switch (name_type) {
     case 0:    f = "Workstation"; break;
@@ -313,9 +313,9 @@ print_data(const unsigned char *buf, int len)
 
 
 static void
-write_bits(unsigned int val, char *fmt)
+write_bits(unsigned int val, const char *fmt)
 {
-    char *p = fmt;
+    const char *p = fmt;
     int i = 0;
 
     while ((p = strchr(fmt, '|'))) {
@@ -356,7 +356,7 @@ unistr(const u_char *s, int *len)
        *len = 1;
     }
 
-    while (l < (sizeof(buf) - 1) && s[0] && s[1] == 0) {
+    while (l < (int)(sizeof(buf) - 1) && s[0] && s[1] == 0) {
        buf[l] = s[0];
        s += 2;
        l++;
@@ -371,7 +371,7 @@ static const u_char *
 smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf)
 {
     int reverse = 0;
-    char *attrib_fmt = "READONLY|HIDDEN|SYSTEM|VOLUME|DIR|ARCHIVE|";
+    const char *attrib_fmt = "READONLY|HIDDEN|SYSTEM|VOLUME|DIR|ARCHIVE|";
     int len;
 
     while (*fmt && buf<maxbuf) {
@@ -396,8 +396,12 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf)
 
            p = strchr(++fmt, '}');
            l = PTR_DIFF(p, fmt);
+
+           if ((unsigned int)l > sizeof(bitfmt) - 1)
+                   l = sizeof(bitfmt)-1;
+
            strncpy(bitfmt, fmt, l);
-           bitfmt[l] = 0;
+           bitfmt[l] = '\0';
            fmt = p + 1;
            write_bits(buf[0], bitfmt);
            buf++;
@@ -572,19 +576,21 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf)
        case 'T':
          {
            time_t t;
-           int x;
+           struct tm *lt;
+           const char *tstring;
+           u_int32_t x;
            x = EXTRACT_LE_32BITS(buf);
 
            switch (atoi(fmt + 1)) {
            case 1:
-               if (x == 0 || x == -1 || x == 0xFFFFFFFF)
+               if (x == 0 || x == 0xFFFFFFFF)
                    t = 0;
                else
                    t = make_unix_date(buf);
                buf += 4;
                break;
            case 2:
-               if (x == 0 || x == -1 || x == 0xFFFFFFFF)
+               if (x == 0 || x == 0xFFFFFFFF)
                    t = 0;
                else
                    t = make_unix_date2(buf);
@@ -595,7 +601,15 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf)
                buf += 8;
                break;
            }
-           printf("%s", t ? asctime(localtime(&t)) : "NULL\n");
+           if (t != 0) {
+               lt = localtime(&t);
+               if (lt != NULL)
+                   tstring = asctime(lt);
+               else
+                   tstring = "(Can't convert time)\n";
+           } else
+               tstring = "NULL\n";
+           printf("%s", tstring);
            fmt++;
            while (isdigit((unsigned char)*fmt))
                fmt++;
@@ -665,7 +679,7 @@ smb_fdata(const u_char *buf, const char *fmt, const u_char *maxbuf)
                return(buf);
            memset(s, 0, sizeof(s));
            p = strchr(fmt, ']');
-           if (p - fmt + 1 > sizeof(s)) {
+           if ((size_t)(p - fmt + 1) > sizeof(s)) {
                /* overrun */
                return(buf);
            }
@@ -792,7 +806,7 @@ err_code_struct hard_msgs[] = {
 
 static struct {
     int code;
-    char *class;
+    const char *class;
     err_code_struct *err_msgs;
 } err_classes[] = {
     { 0, "SUCCESS", NULL },