X-Git-Url: http://git.samba.org/samba.git/?a=blobdiff_plain;f=packet-sip.c;h=f9d5f90bb5d16818b658ff9b01214cba7448ae44;hb=404ac984f539cda172c4af764d071b42656f52b0;hp=4f3e2f063b4352b385bef53e76fe2a9d091119fa;hpb=c65b7aa009880a9bc9bfc51f91c9c70c0e968187;p=obnox%2Fwireshark%2Fwip.git diff --git a/packet-sip.c b/packet-sip.c index 4f3e2f063b..f9d5f90bb5 100644 --- a/packet-sip.c +++ b/packet-sip.c @@ -1,7 +1,7 @@ /* packet-sip.c * Routines for the Session Initiation Protocol (SIP) dissection. * RFC 2543 - * + * * TODO: Pay attention to Content-Type: It might not always be SDP. * Add hf_* fields for filtering support. * Add sip msg body dissection based on Content-Type for: @@ -13,26 +13,26 @@ * check for other * * Copyright 2000, Heikki Vatiainen - * Copyright 2001, Jean-Francois Mule + * Copyright 2001, Jean-Francois Mule * - * $Id: packet-sip.c,v 1.27 2002/05/08 20:29:46 guy Exp $ + * $Id: packet-sip.c,v 1.33 2002/10/02 18:51:10 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs * Copyright 1998 Gerald Combs * * Copied from packet-cops.c - * + * * 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. @@ -82,7 +82,7 @@ static const char *sip_methods[] = { static gboolean sip_is_request(tvbuff_t *tvb, gint eol); static gboolean sip_is_known_request(tvbuff_t *tvb, guint32 offset); static gint sip_get_msg_offset(tvbuff_t *tvb, guint32 offset); - + static dissector_handle_t sdp_handle; static dissector_handle_t data_handle; @@ -107,7 +107,7 @@ static void dissect_sip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * "tvb_get_ptr()" call s below won't throw exceptions. */ offset = 0; - eol = tvb_find_line_end(tvb, 0, -1, &next_offset); + eol = tvb_find_line_end(tvb, 0, -1, &next_offset, FALSE); /* XXX - Check for a valid status message as well. */ is_request = sip_is_request(tvb, eol); is_known_request = sip_is_known_request(tvb, 0); @@ -115,9 +115,9 @@ static void dissect_sip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if (tvb_strneql(tvb, 0, SIP2_HDR, SIP2_HDR_LEN) != 0 && ! is_request) goto bad; - if (check_col(pinfo->cinfo, COL_PROTOCOL)) + if (check_col(pinfo->cinfo, COL_PROTOCOL)) col_set_str(pinfo->cinfo, COL_PROTOCOL, "SIP"); - + req_descr = is_known_request ? "Request" : "Unknown request"; if (check_col(pinfo->cinfo, COL_INFO)) col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s", @@ -153,7 +153,8 @@ static void dissect_sip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* - 2 since we have a CRLF separating the message-body */ while (msg_offset - 2 > (int) offset) { - eol = tvb_find_line_end(tvb, offset, -1, &next_offset); + eol = tvb_find_line_end(tvb, offset, -1, &next_offset, + FALSE); proto_tree_add_text(hdr_tree, tvb, offset, next_offset - offset, "%s", tvb_format_text(tvb, offset, eol)); offset = next_offset; @@ -187,17 +188,44 @@ dissect_sip_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * So we first check if the frame is really meant for us. */ - /* check for a request */ + /* + * Check for a response. + * First, make sure we have enough data to do the check. + */ + if (!tvb_bytes_exist(tvb, 0, SIP2_HDR_LEN)) { + /* + * We don't. + */ + return FALSE; + } + /* + * Now see if we have a response header; they begin with + * "SIP/2.0". + */ if (tvb_strneql(tvb, 0, SIP2_HDR, SIP2_HDR_LEN) != 0) { /* - * Not a request; check for a response. + * We don't, so this isn't a response; check for a request. + * They *end* with "SIP/2.0". */ - eol = tvb_find_line_end(tvb, 0, -1, &next_offset); - if ((eol > (gint)SIP2_HDR_LEN) && - (tvb_strneql(tvb, eol - SIP2_HDR_LEN + 1, SIP2_HDR , SIP2_HDR_LEN - 1) != 0)) { + eol = tvb_find_line_end(tvb, 0, -1, &next_offset, FALSE); + if (eol <= (gint)SIP2_HDR_LEN) { /* - * Not a response, either. + * The line isn't long enough to end with "SIP/2.0". + */ + return FALSE; + } + if (!tvb_bytes_exist(tvb, eol - SIP2_HDR_LEN, SIP2_HDR_LEN)) { + /* + * We don't have enough of the data in the line + * to check. + */ + return FALSE; + } + + if (tvb_strneql(tvb, eol - SIP2_HDR_LEN, SIP2_HDR, SIP2_HDR_LEN - 1) != 0) { + /* + * Not a request, either. */ return FALSE; } @@ -211,7 +239,6 @@ dissect_sip_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) return TRUE; } - /* Returns the offset to the start of the optional message-body, or * -1 if not found. */ @@ -221,8 +248,8 @@ static gint sip_get_msg_offset(tvbuff_t *tvb, guint32 offset) while ((eol = tvb_find_guint8(tvb, offset, -1, '\r')) > 0 && tvb_bytes_exist(tvb, eol, 4)) { - if (tvb_get_guint8(tvb, eol + 1) == '\n' && - tvb_get_guint8(tvb, eol + 2) == '\r' && + if (tvb_get_guint8(tvb, eol + 1) == '\n' && + tvb_get_guint8(tvb, eol + 2) == '\r' && tvb_get_guint8(tvb, eol + 3) == '\n') return eol + 4; offset = eol + 2; @@ -234,7 +261,7 @@ static gint sip_get_msg_offset(tvbuff_t *tvb, guint32 offset) /* From section 4.1 of RFC 2543: * * Request-Line = Method SP Request-URI SP SIP-Version CRLF - */ + */ static gboolean sip_is_request(tvbuff_t *tvb, gint eol) { @@ -260,7 +287,7 @@ static gboolean sip_is_request(tvbuff_t *tvb, gint eol) if (req_colon_pos < 0 || req_colon_pos > ver_start) return FALSE; /* XXX - Check for a proper URI prefix? */ - + /* Do we have a proper version string? */ if (tvb_strneql(tvb, ver_start, SIP2_HDR, SIP2_HDR_LEN)) return TRUE; @@ -284,7 +311,7 @@ static gboolean sip_is_known_request(tvbuff_t *tvb, guint32 offset) /* Register the protocol with Ethereal */ void proto_register_sip(void) -{ +{ /* Setup list of header fields */ static hf_register_info hf[] = {