diff options
author | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2013-08-20 19:56:57 +0000 |
---|---|---|
committer | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2013-08-20 19:56:57 +0000 |
commit | c27481b03cf6a9a91d013d19ed0fd6eb48ddf23e (patch) | |
tree | d0a9b255b6737feed0b15942bd37deb0afdab651 /epan/tvbuff.c | |
parent | 8ade8c4750e6923d25fd804906023a792e9381d6 (diff) |
Fix for bug #9034: Composite TVBs aren't supported by tvb_find_guint8()
Add generic tvb_find_guint8, tvb_pbrk_guint8
svn path=/trunk/; revision=51445
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r-- | epan/tvbuff.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 6951d8e2cd..99a51b9863 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -1496,6 +1496,21 @@ tvb_get_bits(tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits, const return (guint32)_tvb_get_bits64(tvb, bit_offset, no_of_bits); } +static gint +tvb_find_guint8_generic(tvbuff_t *tvb, guint abs_offset, guint limit, guint8 needle) +{ + const guint8 *ptr; + const guint8 *result; + + ptr = tvb_get_ptr(tvb, abs_offset, limit); + + result = (const guint8 *) memchr(ptr, needle, limit); + if (!result) + return -1; + + return (gint) ((result - ptr) + abs_offset); +} + /* Find first occurrence of needle in tvbuff, starting at offset. Searches * at most maxlength number of bytes; if maxlength is -1, searches to * end of tvbuff. @@ -1545,10 +1560,22 @@ tvb_find_guint8(tvbuff_t *tvb, const gint offset, const gint maxlength, const gu if (tvb->ops->tvb_find_guint8) return tvb->ops->tvb_find_guint8(tvb, abs_offset, limit, needle); - /* XXX, fallback to slower method */ + return tvb_find_guint8_generic(tvb, offset, limit, needle); +} - DISSECTOR_ASSERT_NOT_REACHED(); - return -1; +static gint +tvb_pbrk_guint8_generic(tvbuff_t *tvb, guint abs_offset, guint limit, const guint8 *needles, guchar *found_needle) +{ + const guint8 *ptr; + const guint8 *result; + + ptr = tvb_get_ptr(tvb, abs_offset, limit); + + result = guint8_pbrk(ptr, limit, needles, found_needle); + if (!result) + return -1; + + return (gint) ((result - ptr) + abs_offset); } /* Find first occurrence of any of the needles in tvbuff, starting at offset. @@ -1600,9 +1627,7 @@ tvb_pbrk_guint8(tvbuff_t *tvb, const gint offset, const gint maxlength, const gu if (tvb->ops->tvb_pbrk_guint8) return tvb->ops->tvb_pbrk_guint8(tvb, abs_offset, limit, needles, found_needle); - /* XXX, fallback to slower method */ - DISSECTOR_ASSERT_NOT_REACHED(); - return -1; + return tvb_pbrk_guint8_generic(tvb, abs_offset, limit, needles, found_needle); } /* Find size of stringz (NUL-terminated string) by looking for terminating |