diff options
author | Guy Harris <guy@alum.mit.edu> | 2019-12-26 02:55:27 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2019-12-26 18:08:27 +0000 |
commit | a81c8e57bfb3596c552d49cf66fa695e0391406d (patch) | |
tree | 0ca896b9a7e56f3538367f5f2577016aaf00ef13 /epan | |
parent | f0be7f27d862a5f460b398693fe4731e7ed87aa8 (diff) |
Find the line ending using tvb_find_line_end().
tvb_find_line_end(), unlike a tvb_find_guint8() looking for an LF,
returns a length that *doesn't* include the line ending, *regardless* of
whether the line ends with CR-LF or just LF, so the query string we
extract is just the query, without any of the line ending.
Update some comments while we're at it to note that the "next_offset"
pointer argument to tvb_find_line_end() and tvb_find_line_end_unquoted()
can be NULL, in which case the offset *past* the line ending isn't
returned. (We pass tvb_find_line_end() NULL in the aforementioned call,
because, in that particular case, we don't care about the next line.)
Change-Id: I1c9746e32c61a79f8cb636d577a2e14a07ecab17
Reviewed-on: https://code.wireshark.org/review/35566
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dissectors/packet-whois.c | 12 | ||||
-rw-r--r-- | epan/tvbuff.c | 12 | ||||
-rw-r--r-- | epan/tvbuff.h | 12 |
3 files changed, 20 insertions, 16 deletions
diff --git a/epan/dissectors/packet-whois.c b/epan/dissectors/packet-whois.c index 7e5870cc9f..3dda13ae20 100644 --- a/epan/dissectors/packet-whois.c +++ b/epan/dissectors/packet-whois.c @@ -61,11 +61,15 @@ dissect_whois(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, conversation = find_or_create_conversation(pinfo); whois_trans = (whois_transaction_t *)conversation_get_proto_data(conversation, proto_whois); if (whois_trans == NULL) { - gint newline; + gint linelen; whois_trans = wmem_new0(wmem_file_scope(), whois_transaction_t); - newline = tvb_find_guint8(tvb, 0, -1, '\n'); - if (newline != -1) - whois_trans->query = tvb_get_string_enc(wmem_file_scope(), tvb, 0, newline, ENC_ASCII|ENC_NA); + + /* + * Find the end of the first line. + */ + linelen = tvb_find_line_end(tvb, 0, -1, NULL, FALSE); + if (linelen != -1) + whois_trans->query = tvb_get_string_enc(wmem_file_scope(), tvb, 0, linelen, ENC_ASCII|ENC_NA); conversation_add_proto_data(conversation, proto_whois, whois_trans); } diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 73cb88ef50..a5a8d24503 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -3503,9 +3503,9 @@ static ws_mempbrk_pattern pbrk_crlf; * if "desegment" is false, return the amount of data remaining in * the buffer. * - * Set "*next_offset" to the offset of the character past the line - * terminator, or past the end of the buffer if we don't find a line - * terminator. (It's not set if we return -1.) + * If "next_offset" is not NULL, set "*next_offset" to the offset of the + * character past the line terminator, or past the end of the buffer if + * we don't find a line terminator. (It's not set if we return -1.) */ gint tvb_find_line_end(tvbuff_t *tvb, const gint offset, int len, gint *next_offset, const gboolean desegment) @@ -3626,9 +3626,9 @@ static ws_mempbrk_pattern pbrk_crlf_dquote; * the end), or the amount of data remaining in the buffer if we don't * find a line terminator. * - * Set "*next_offset" to the offset of the character past the line - * terminator, or past the end of the buffer if we don't find a line - * terminator. + * If "next_offset" is not NULL, set "*next_offset" to the offset of the + * character past the line terminator, or past the end of the buffer if + * we don't find a line terminator. */ gint tvb_find_line_end_unquoted(tvbuff_t *tvb, const gint offset, int len, gint *next_offset) diff --git a/epan/tvbuff.h b/epan/tvbuff.h index 6a048ed296..002cc13e53 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -762,9 +762,9 @@ WS_DLL_PUBLIC gboolean tvb_ascii_isprint(tvbuff_t *tvb, const gint offset, * if "deseg" is false, return the amount of data remaining in * the buffer. * - * Set "*next_offset" to the offset of the character past the line - * terminator, or past the end of the buffer if we don't find a line - * terminator. (It's not set if we return -1.) + * If "next_offset" is not NULL, set "*next_offset" to the offset of the + * character past the line terminator, or past the end of the buffer if + * we don't find a line terminator. (It's not set if we return -1.) */ WS_DLL_PUBLIC gint tvb_find_line_end(tvbuff_t *tvb, const gint offset, int len, gint *next_offset, const gboolean desegment); @@ -783,9 +783,9 @@ WS_DLL_PUBLIC gint tvb_find_line_end(tvbuff_t *tvb, const gint offset, int len, * the end), or the amount of data remaining in the buffer if we don't * find a line terminator. * - * Set "*next_offset" to the offset of the character past the line - * terminator, or past the end of the buffer if we don't find a line - * terminator. + * If "next_offset" is not NULL, set "*next_offset" to the offset of the + * character past the line terminator, or past the end of the buffer if + * we don't find a line terminator. */ WS_DLL_PUBLIC gint tvb_find_line_end_unquoted(tvbuff_t *tvb, const gint offset, int len, gint *next_offset); |