aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2000-08-06 10:04:15 +0000
committerGuy Harris <guy@alum.mit.edu>2000-08-06 10:04:15 +0000
commita056a4d4469a97fed144343020231083889aa987 (patch)
tree8674f6a4991e831c2e63ca459e868b72e3b29846
parentef5f866b73430d1df38f2fdd0df16a6d83598744 (diff)
downloadwireshark-a056a4d4469a97fed144343020231083889aa987.tar.gz
wireshark-a056a4d4469a97fed144343020231083889aa987.tar.bz2
wireshark-a056a4d4469a97fed144343020231083889aa987.zip
Use "BYTES_ARE_IN_FRAME()" rather than explicitly checking an offset and
packet length. Use "IS_DATA_IN_FRAME()", rather than checking if "offset+1" is greater than "pi.captured_len", to check whether there's any data left in the packet. Check whether data is in the packet *before* extracting it and stuffing an item into the tree with it. svn path=/trunk/; revision=2216
-rw-r--r--packet-msproxy.c6
-rw-r--r--packet-smb-logon.c27
-rw-r--r--packet-socks.c18
3 files changed, 28 insertions, 23 deletions
diff --git a/packet-msproxy.c b/packet-msproxy.c
index a519841f2c..6ac41a644f 100644
--- a/packet-msproxy.c
+++ b/packet-msproxy.c
@@ -2,7 +2,7 @@
* Routines for Microsoft Proxy packet dissection
* Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
*
- * $Id: packet-msproxy.c,v 1.5 2000/08/06 07:22:34 guy Exp $
+ * $Id: packet-msproxy.c,v 1.6 2000/08/06 10:04:13 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -78,7 +78,7 @@
# include "snprintf.h"
#endif
-#define CHECK_PACKET_LENGTH(X) if ((offset+X) > pi.captured_len){ \
+#define CHECK_PACKET_LENGTH(X) if (!BYTES_ARE_IN_FRAME(offset, X)){ \
proto_tree_add_text(tree, NullTVB, offset, 0, "****FRAME TOO SHORT***"); return;}
extern void udp_hash_add(guint16 proto,
@@ -323,7 +323,7 @@ static int display_application_name(const u_char *pd, int offset,
char temp[255];
- if ((offset+ 1) > pi.captured_len){
+ if (!IS_DATA_IN_FRAME(offset)){
proto_tree_add_text(tree, NullTVB, offset, 0, "****FRAME TOO SHORT***");
return 0;
}
diff --git a/packet-smb-logon.c b/packet-smb-logon.c
index ad41657ecf..2ae6667573 100644
--- a/packet-smb-logon.c
+++ b/packet-smb-logon.c
@@ -2,7 +2,7 @@
* Routines for smb net logon packet dissection
* Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
*
- * $Id: packet-smb-logon.c,v 1.6 2000/08/06 07:22:37 guy Exp $
+ * $Id: packet-smb-logon.c,v 1.7 2000/08/06 10:04:14 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -75,7 +75,14 @@ display_LM_token( const u_char *pd, int *offset, frame_data *fd,
/* decode and display the LanMan token */
- guint16 Token = GSHORT( pd, *offset);
+ guint16 Token;
+
+ if (!BYTES_ARE_IN_FRAME(*offset, 2)) {
+ proto_tree_add_text(tree, NullTVB, *offset, 0,"****FRAME TOO SHORT***");
+ return;
+ }
+
+ Token = GSHORT( pd, *offset);
if ( Token && 0x01)
proto_tree_add_text( tree, NullTVB, *offset, 2,
@@ -83,11 +90,7 @@ display_LM_token( const u_char *pd, int *offset, frame_data *fd,
else
proto_tree_add_text( tree, NullTVB, *offset, 2,
"LM10 Token: 0x%x (WFW Networking)", Token);
-
- if (( *offset + 2) > pi.captured_len)
- proto_tree_add_text(tree, NullTVB, *offset, 0,"****FRAME TOO SHORT***");
- else
- *offset += 2;
+ *offset += 2;
}
@@ -99,6 +102,11 @@ display_NT_version( const u_char *pd, int *offset, frame_data *fd,
guint32 Version;
+ if (!BYTES_ARE_IN_FRAME(*offset, length)) {
+ proto_tree_add_text(tree, NullTVB, *offset, 0, "****FRAME TOO SHORT***");
+ return;
+ }
+
if ( length == 2)
Version = GSHORT( pd, *offset);
else
@@ -107,10 +115,7 @@ display_NT_version( const u_char *pd, int *offset, frame_data *fd,
proto_tree_add_text( tree, NullTVB, *offset, length, "NT Version: 0x%x ",
Version);
- if (( *offset + length) > pi.captured_len)
- proto_tree_add_text(tree, NullTVB, *offset, 0, "****FRAME TOO SHORT***");
- else
- *offset += length;
+ *offset += length;
}
diff --git a/packet-socks.c b/packet-socks.c
index 62faa64703..aae33c7c96 100644
--- a/packet-socks.c
+++ b/packet-socks.c
@@ -2,7 +2,7 @@
* Routines for socks versions 4 &5 packet dissection
* Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
*
- * $Id: packet-socks.c,v 1.6 2000/08/06 07:22:38 guy Exp $
+ * $Id: packet-socks.c,v 1.7 2000/08/06 10:04:15 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -83,7 +83,7 @@
-#define CHECK_PACKET_LENGTH(X) if ((offset+X) > pi.captured_len){ \
+#define CHECK_PACKET_LENGTH(X) if (!BYTES_ARE_IN_FRAME(offset, X)){ \
proto_tree_add_text(tree, NullTVB, offset, 0, "*** FRAME TOO SHORT ***"); \
return; }
@@ -233,7 +233,7 @@ static int display_string( const u_char *pd, int offset, frame_data *fd,
char temp[ 256];
int length = GBYTE( pd, offset);
- if ((offset + 8) > pi.captured_len){
+ if (!BYTES_ARE_IN_FRAME(offset, 8)){
proto_tree_add_text(tree, NullTVB, offset, 0, "*** FRAME TOO SHORT ***");
return 0;
}
@@ -305,7 +305,7 @@ static int display_address( const u_char *pd, int offset,
++offset;
if ( a_type == 1){ /* IPv4 address */
- if ( (offset + 4) > pi.captured_len)
+ if (!BYTES_ARE_IN_FRAME(offset, 4))
proto_tree_add_text(tree, NullTVB, offset, 0, "*** FRAME TOO SHORT ***");
proto_tree_add_ipv4( tree, hf_socks_ip_dst, NullTVB, offset,
@@ -318,7 +318,7 @@ static int display_address( const u_char *pd, int offset,
"Remote name");
}
else if ( a_type == 4){ /* IPv6 address */
- if ((offset + 16) > pi.captured_len)
+ if (!BYTES_ARE_IN_FRAME(offset, 16))
proto_tree_add_text(tree, NullTVB, offset, 0, "*** FRAME TOO SHORT ***");
proto_tree_add_ipv6( tree, hf_socks_ip6_dst, NullTVB, offset,
@@ -739,7 +739,7 @@ static void state_machine_v5( socks_hash_entry_t *hash_info, const u_char *pd,
hash_info->state = Connecting; /* change state */
hash_info->connect_row = get_packet_ptr;
- if (( offset+ 1) > pi.captured_len){
+ if (!BYTES_ARE_IN_FRAME(offset, 1)){
hash_info->state = Done; /* change state */
return;
}
@@ -775,7 +775,7 @@ static void state_machine_v5( socks_hash_entry_t *hash_info, const u_char *pd,
guint temp;
- if (( offset+ 1) > pi.captured_len){
+ if (!BYTES_ARE_IN_FRAME(offset, 1)){
hash_info->state = Done; /* change state */
return;
}
@@ -793,7 +793,7 @@ static void state_machine_v5( socks_hash_entry_t *hash_info, const u_char *pd,
offset = get_address_v5( pd, offset, hash_info);
- if (( offset+ 1) > pi.captured_len){
+ if (!BYTES_ARE_IN_FRAME(offset, 1)){
hash_info->state = Done;
return;
}
@@ -827,7 +827,7 @@ static void state_machine_v5( socks_hash_entry_t *hash_info, const u_char *pd,
offset = get_address_v5( pd, offset, hash_info);
/* save server udp port and create upd conversation */
- if (( offset+ 2) > pi.captured_len){
+ if (!BYTES_ARE_IN_FRAME(offset, 2)){
hash_info->state = Done;
return;
}