Updates from Ed Warnicke.
[obnox/wireshark/wip.git] / packet-smb.c
index 4ad21712b5a37ac849ef8c041bff1e750099e6f7..0f43553ac6d87e9ce20275505183804a545712ca 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for smb packet dissection
  * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
  *
- * $Id: packet-smb.c,v 1.71 2000/08/13 14:08:50 deniel Exp $
+ * $Id: packet-smb.c,v 1.76 2000/12/17 03:48:44 sharpe Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -47,6 +47,7 @@
 #include "conversation.h"
 #include "smb.h"
 #include "alignment.h"
+#include "strutil.h"
 
 guint32 dissect_mailslot_smb(const u_char *, int, frame_data *, proto_tree *, proto_tree *, struct smb_info, int, int, int, int, const u_char *, int, int, int, int);
 
@@ -706,12 +707,16 @@ static char *
 dissect_smbu_date(guint16 date, guint16 time)
 
 {
-  static char         datebuf[4+2+2+2+1];
+  static char         datebuf[4+2+2+2+1+10];
   time_t              ltime = (date << 16) + time;
 
   _gtime = gmtime(&ltime);
-  sprintf(datebuf, "%04d-%02d-%02d",
-         1900 + (_gtime -> tm_year), 1 + (_gtime -> tm_mon), _gtime -> tm_mday);
+
+  if (_gtime)
+    sprintf(datebuf, "%04d-%02d-%02d",
+           1900 + (_gtime -> tm_year), 1 + (_gtime -> tm_mon), _gtime -> tm_mday);
+  else 
+    sprintf(datebuf, "Bad date format");
 
   return datebuf;
 
@@ -724,10 +729,13 @@ static char *
 dissect_smbu_time(guint16 date, guint16 time)
 
 {
-  static char timebuf[2+2+2+2+1];
+  static char timebuf[2+2+2+2+1+10];
 
-  sprintf(timebuf, "%02d:%02d:%02d",
-          _gtime -> tm_hour, _gtime -> tm_min, _gtime -> tm_sec);
+  if (_gtime)
+    sprintf(timebuf, "%02d:%02d:%02d",
+           _gtime -> tm_hour, _gtime -> tm_min, _gtime -> tm_sec);
+  else
+    sprintf(timebuf, "Bad time format");
 
   return timebuf;
 
@@ -8219,7 +8227,7 @@ dissect_get_file_attr_smb(const u_char *pd, int offset, frame_data *fd, proto_tr
 
        proto_tree_add_text(tree, NullTVB, offset, 2, "Last Write Date: %s", dissect_smbu_date(LastWriteDate, LastWriteTime));
 
-       proto_tree_add_text(tree, NullTVB, offset, 2, "Last Write Time: %s", dissect_smbu_time(LastWriteDate, LastWriteTime));
+       proto_tree_add_text(tree, NullTVB, offset - 2, 2, "Last Write Time: %s", dissect_smbu_time(LastWriteDate, LastWriteTime));
 
       }
 
@@ -8891,11 +8899,11 @@ dissect_transact2_smb(const u_char *pd, int offset, frame_data *fd, proto_tree *
    * packets from B:Y to A:X.
    */
   conversation = find_conversation(&pi.src, &pi.dst, pi.ptype,
-                               pi.srcport, pi.destport);
+                               pi.srcport, pi.destport, 0);
   if (conversation == NULL) {
     /* It's not part of any conversation - create a new one. */
     conversation = conversation_new(&pi.src, &pi.dst, pi.ptype,
-                               pi.srcport, pi.destport, NULL);
+                               pi.srcport, pi.destport, NULL, 0);
   }
 
   si.conversation = conversation;  /* Save this for later */
@@ -9506,14 +9514,14 @@ dissect_transact_params(const u_char *pd, int offset, frame_data *fd, proto_tree
   if (!TransactName)
          return;
 
-  TransactNameCopy = g_malloc(strlen(TransactName) + 1);
+  TransactNameCopy = g_malloc(TransactName ? strlen(TransactName) + 1 : 1);
 
   /* Should check for error here ... */
 
-  strcpy(TransactNameCopy, TransactName);
+  strcpy(TransactNameCopy, TransactName ? TransactName : "");
   if (TransactNameCopy[0] == '\\') {
     trans_type = TransactNameCopy + 1;  /* Skip the slash */
-    loc_of_slash = strchr(trans_type, '\\');
+    loc_of_slash = trans_type ? strchr(trans_type, '\\') : NULL;
   }
 
   if (loc_of_slash) {
@@ -9525,9 +9533,9 @@ dissect_transact_params(const u_char *pd, int offset, frame_data *fd, proto_tree
     trans_cmd = NULL;
 
   if ((trans_cmd == NULL) ||
-      (((strcmp(trans_type, "MAILSLOT") != 0) ||
+      (((trans_type == NULL || strcmp(trans_type, "MAILSLOT") != 0) ||
        !dissect_mailslot_smb(pd, SetupAreaOffset, fd, parent, tree, si, max_data, SMB_offset, errcode, dirn, trans_cmd, SMB_offset + DataOffset, DataCount, SMB_offset + ParameterOffset, ParameterCount)) &&
-      ((strcmp(trans_type, "PIPE") != 0) ||
+      ((trans_type == NULL || strcmp(trans_type, "PIPE") != 0) ||
        !dissect_pipe_smb(pd, offset, fd, parent, tree, si, max_data, SMB_offset, errcode, dirn, trans_cmd, DataOffset, DataCount, ParameterOffset, ParameterCount)))) {
     
     if (ParameterCount > 0) {
@@ -9619,12 +9627,12 @@ dissect_transact_smb(const u_char *pd, int offset, frame_data *fd, proto_tree *p
    */
 
   conversation = find_conversation(&pi.src, &pi.dst, pi.ptype,
-                                  pi.srcport, pi.destport);
+                                  pi.srcport, pi.destport, 0);
 
   if (conversation == NULL) {  /* Create a new conversation */
 
     conversation = conversation_new(&pi.src, &pi.dst, pi.ptype,
-                                   pi.srcport, pi.destport, NULL);
+                                   pi.srcport, pi.destport, NULL, 0);
 
   }
 
@@ -10602,7 +10610,7 @@ dissect_smb(const u_char *pd, int offset, frame_data *fd, proto_tree *tree, int
        cmd = pd[offset + SMB_hdr_com_offset];
 
        if (check_col(fd, COL_PROTOCOL))
-               col_add_str(fd, COL_PROTOCOL, "SMB");
+               col_set_str(fd, COL_PROTOCOL, "SMB");
 
        /* Hmmm, poor coding here ... Also, should check the type */