]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-smb.c
add lwres dissector
[tcpdump] / print-smb.c
index 414bea38f8587577cefdc9ef8cb2755ee1c3fb08..debcb6544aacfb8ac1d34d2637b3413b587d5568 100644 (file)
@@ -11,7 +11,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/print-smb.c,v 1.6 2000-12-04 00:35:44 guy Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/print-smb.c,v 1.9 2001-01-15 03:59:14 guy Exp $";
 #endif
 
 #include <stdio.h>
@@ -918,8 +918,10 @@ out:
 void nbt_udp138_print(const uchar *data, int length)
 {
   const uchar *maxbuf = data + length;
-  startbuf = data;
+
+  if (maxbuf > snapend) maxbuf = snapend;
   if (maxbuf <= data) return;
+  startbuf = data;
 
   data = fdata(data,"\n>>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[rd] Length=[rd] Res2=[rw]\nSourceName=[n1]\nDestName=[n1]\n#",maxbuf);
 
@@ -935,15 +937,30 @@ void nbt_udp138_print(const uchar *data, int length)
 /*
    print netbeui frames 
 */
-void netbeui_print(const uchar *data, const uchar *maxbuf)
+void netbeui_print(u_short control, const uchar *data, int length)
 {
-  int len = SVAL(data,1);
-  int command = CVAL(data,5);
-  const uchar *data2 = data + 1 + len;
+  const uchar *maxbuf = data + length;
+  int len;
+  int command;
+  const uchar *data2;
+  int is_truncated = 0;
+
+  if (maxbuf > snapend)
+    maxbuf = snapend;
+  if (&data[7] >= maxbuf)
+    goto out;
+  len = SVAL(data,0);
+  command = CVAL(data,4);
+  data2 = data + len;
+  if (data2 >= maxbuf) {
+    data2 = maxbuf;
+    is_truncated = 1;
+  }
 
   startbuf = data;
 
-  data = fdata(data,"\n>>> NetBeui Packet\nType=[B] Length=[d] Signature=[w] Command=[B]\n#",maxbuf);
+  printf("\n>>> NetBeui Packet\nType=0x%X ", control);
+  data = fdata(data,"Length=[d] Signature=[w] Command=[B]\n#",maxbuf);
   if (data == NULL)
     goto out;
 
@@ -980,6 +997,10 @@ void netbeui_print(const uchar *data, const uchar *maxbuf)
     data = fdata(data,"SessionEnd:\n[P1]Data2=[w][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2);
     break;
 
+  case 0x1f:
+    data = fdata(data,"SessionAlive\n",data2);
+    break;
+
   default:
     data = fdata(data,"Unknown Netbios Command ",data2);
     break;
@@ -987,11 +1008,22 @@ void netbeui_print(const uchar *data, const uchar *maxbuf)
   if (data == NULL)
     goto out;
 
+  if (is_truncated) {
+    /* data2 was past the end of the buffer */
+    goto out;
+  }
+
+  /* If there isn't enough data for "\377SMB", don't look for it. */
+  if (&data2[3] >= maxbuf)
+    goto out;
+
   if (memcmp(data2,"\377SMB",4)==0) {
     print_smb(data2,maxbuf);
   } else {
     int i;
     for (i=0;i<128;i++) {
+      if (&data2[i+3] >= maxbuf)
+        break;
       if (memcmp(&data2[i],"\377SMB",4)==0) {
        printf("found SMB packet at %d\n", i);
        print_smb(&data2[i],maxbuf);
@@ -1008,12 +1040,21 @@ out:
 /*
    print IPX-Netbios frames 
 */
-void ipx_netbios_print(const uchar *data, const uchar *maxbuf)
+void ipx_netbios_print(const uchar *data, u_int length)
 {
-  /* this is a hack till I work out how to parse the rest of the IPX stuff */
+  /* this is a hack till I work out how to parse the rest of the
+     NetBIOS-over-IPX stuff */
   int i;
+  const uchar *maxbuf;
+
+  maxbuf = data + length;
+  /* Don't go past the end of the captured data in the packet. */
+  if (maxbuf > snapend)
+    maxbuf = snapend;
   startbuf = data;
-  for (i=0;i<128;i++)
+  for (i=0;i<128;i++) {
+    if (&data[i+3] >= maxbuf)
+      break;
     if (memcmp(&data[i],"\377SMB",4)==0) {
       fdata(data,"\n>>> IPX transport ",&data[i]);
       if (data != NULL)
@@ -1022,6 +1063,7 @@ void ipx_netbios_print(const uchar *data, const uchar *maxbuf)
       fflush(stdout);
       break;
     }
+  }
   if (i==128)
     fdata(data,"\n>>> Unknown IPX ",maxbuf);
 }