]> The Tcpdump Group git mirrors - tcpdump/blobdiff - smbutil.c
add tracefiles for infinite loop testing
[tcpdump] / smbutil.c
index 729885fcb31fedd653846da1697bc288b2212fa3..418779a9f27c7cbb5b755e7c7035b0407fe814b2 100644 (file)
--- a/smbutil.c
+++ b/smbutil.c
 #endif
 
 #ifndef lint
-static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.20 2002-04-25 04:54:03 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 <sys/param.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+#include <tcpdump-stdinc.h>
 
-#include <netinet/in.h>
-
-#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifdef TIME_WITH_SYS_TIME
-#include <time.h>
-#endif
 
 #include "interface.h"
 #include "extract.h"
@@ -261,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;
@@ -322,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, '|'))) {
@@ -365,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++;
@@ -380,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) {
@@ -405,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++;
@@ -418,7 +413,7 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf)
            int l = atoi(fmt + 1);
            buf += l;
            fmt++;
-           while (isdigit(*fmt))
+           while (isdigit((unsigned char)*fmt))
                fmt++;
            break;
          }
@@ -532,7 +527,7 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf)
            printf("%-*.*s", l, l, buf);
            buf += l;
            fmt++;
-           while (isdigit(*fmt))
+           while (isdigit((unsigned char)*fmt))
                fmt++;
            break;
          }
@@ -542,7 +537,7 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf)
            while (l--)
                printf("%02x", *buf++);
            fmt++;
-           while (isdigit(*fmt))
+           while (isdigit((unsigned char)*fmt))
                fmt++;
            break;
          }
@@ -574,26 +569,28 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf)
                break;
            }
            fmt++;
-           while (isdigit(*fmt))
+           while (isdigit((unsigned char)*fmt))
                fmt++;
            break;
          }
        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);
@@ -604,9 +601,17 @@ 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(*fmt))
+           while (isdigit((unsigned char)*fmt))
                fmt++;
            break;
          }
@@ -674,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);
            }
@@ -801,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 },