Look for out of bounds data after calling tvb_length_remaining().
[obnox/wireshark/wip.git] / packet-icap.c
index 056cf8aac1d57f37d2d927e0c795946f1f75a458..b3d310bc234ec68546746af5e1c5f1c6b965b63a 100644 (file)
@@ -3,22 +3,22 @@
  *
  * Srishylam Simharajan simha@netapp.com
  *
- * packet-icap.c Mon Aug 13 17:50:19 PDT 2001 simha 
+ * $Id: packet-icap.c,v 1.12 2002/08/28 21:00:17 jmayer Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
- * 
+ *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "config.h"
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
 #include <string.h>
 #include <ctype.h>
 
@@ -59,18 +55,18 @@ static gint ett_icap = -1;
 static dissector_handle_t data_handle;
 
 #define TCP_PORT_ICAP                  1344
-static int is_icap_message(const u_char *data, int linelen, icap_type_t *type);
+static int is_icap_message(const guchar *data, int linelen, icap_type_t *type);
 static void
 dissect_icap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
        proto_tree      *icap_tree = NULL;
        proto_item      *ti = NULL;
        gint            offset = 0;
-       const u_char    *line;
+       const guchar    *line;
        gint            next_offset;
-       const u_char    *linep, *lineend;
+       const guchar    *linep, *lineend;
        int             linelen;
-       u_char          c;
+       guchar          c;
        icap_type_t     icap_type;
        int             datalen;
 
@@ -88,7 +84,8 @@ dissect_icap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                 * is not longer than what's in the buffer, so the
                 * "tvb_get_ptr()" call won't throw an exception.
                 */
-               linelen = tvb_find_line_end(tvb, offset, -1, &next_offset);
+               linelen = tvb_find_line_end(tvb, offset, -1, &next_offset,
+                   FALSE);
                line = tvb_get_ptr(tvb, offset, linelen);
                icap_type = ICAP_OTHER; /* type not known yet */
                if (is_icap_message(line, linelen, &icap_type))
@@ -114,7 +111,8 @@ dissect_icap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                /*
                 * Find the end of the line.
                 */
-               linelen = tvb_find_line_end(tvb, offset, -1, &next_offset);
+               linelen = tvb_find_line_end(tvb, offset, -1, &next_offset,
+                   FALSE);
 
                /*
                 * Get a buffer that refers to the line.
@@ -231,9 +229,9 @@ is_icap_header:
        }
 }
 
-       
+
 static int
-is_icap_message(const u_char *data, int linelen, icap_type_t *type)
+is_icap_message(const guchar *data, int linelen, icap_type_t *type)
 {
 #define ICAP_COMPARE(string, length, msgtype) {                \
        if (strncmp(data, string, length) == 0) {       \
@@ -247,10 +245,10 @@ is_icap_message(const u_char *data, int linelen, icap_type_t *type)
         */
        if (linelen >= 5) {
                ICAP_COMPARE("ICAP/", 5, ICAP_RESPONSE); /* response */
-       } 
+       }
        if (linelen >= 7) {
                ICAP_COMPARE("REQMOD ", 7, ICAP_REQMOD); /* request mod */
-       } 
+       }
        if (linelen >= 8) {
                ICAP_COMPARE("OPTIONS ", 8, ICAP_OPTIONS); /* options */
                ICAP_COMPARE("RESPMOD ", 8, ICAP_RESPMOD); /* response mod */
@@ -264,7 +262,7 @@ proto_register_icap(void)
 {
        static hf_register_info hf[] = {
            { &hf_icap_response,
-             { "Response",             "icap.response",  
+             { "Response",             "icap.response",
                FT_BOOLEAN, BASE_NONE, NULL, 0x0,
                "TRUE if ICAP response", HFILL }},
            { &hf_icap_reqmod,
@@ -289,7 +287,7 @@ proto_register_icap(void)
        };
 
        proto_icap = proto_register_protocol(
-                       "Internet Content Adaptation Protocol", 
+                       "Internet Content Adaptation Protocol",
                        "ICAP", "icap");
        proto_register_field_array(proto_icap, hf, array_length(hf));
        proto_register_subtree_array(ett, array_length(ett));