Commit Graph

386 Commits

Author SHA1 Message Date
Jakub Zawadzki f3ed13c22e tvbuff: replace type with operation vtable
It's begin of work to allow adding new tvbuff types (think: wtap_tvbuff, base64_tvbuff).

svn path=/trunk/; revision=50486
2013-07-10 18:14:15 +00:00
Jakub Zawadzki 83322789d1 tvbuff: use ep_strbuf_append_unichar()
svn path=/trunk/; revision=50477
2013-07-09 23:10:04 +00:00
Jakub Zawadzki 398f94dd24 tvb subset: move setting tvb->ds_tvb to tvb_new_with_subset()
svn path=/trunk/; revision=50464
2013-07-09 16:22:53 +00:00
Chris Maynard 9a394ddfa0 Get rid of variable, 'end'.
svn path=/trunk/; revision=50285
2013-07-01 06:03:35 +00:00
Chris Maynard 8976968f4c There are a few dissectors that pass the return value of tvb_length_remaining() as the size argument to the tvb_format_*() functions. Try to do something sane if that value happens to be -1 (or negative in general). One such example is packet-bthfp.c, as found and reported by Coverity in CID 1035325 (Improper use of negative value).
Note: There are other ways to handle this of course, but this fix is suitable for backporting to both 1.10 and 1.8, as it does not break binary compatibility.  Is there a better way to fix this though?  For now, schedule this for backport.

svn path=/trunk/; revision=50282
2013-07-01 05:23:17 +00:00
Jeff Morriss 86744b65da As suggested by Jakub: don't ep_alloc buffers for TVBs, use g_malloc()'d
memory with tvb-free-callback.

Fixes one of the "read after free" warnings from Valgrind reported in
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8197 and the one reported
in https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8653

svn path=/trunk/; revision=49379
2013-05-17 14:38:36 +00:00
Guy Harris 09e0d5b406 When creating a subset tvbuff, inherit the flags from the tvbuff of
which we're making a subset, so that if the parent tvbuff is marked as a
fragment, the child tvbuff will be marked as one as well.

svn path=/trunk/; revision=48953
2013-04-21 17:38:57 +00:00
Guy Harris 0efcd0632b When we're dissecting the beginning of a fragmented packet that we
haven't reassembled, we're probably moving sequentially through the
packet, which means that we'll run past the end of the fragment rather
than past the end of what would have been the reassembled packet had we
reassembled it.

I.e., there's little reason to care whether we're past the end of the
fragment but not past the end of the packet, or whether we're past the
end of the packet; in either case, we're past the end of the fragment,
and if somebody wants to know whether the packet is malformed by
stopping short of certain fields, they should enable reassembly.

So we get rid of the explicit fragment length in tvbuffs and, instead,
have a "this is a fragment" flag; if that flag is set, we throw
FragmentBoundsError rather than ReportedBoundsError if we run past the
end of the reported data.

(This also means we could flag the tvbuff even if we don't know how
large the reassembled packet will be, e.g. when doing IP reassembly.)

Replace tvb_new_subset_length_fragment() with tvb_new_subset_length()
and a new "set the "this is a fragment flag"" routine.

svn path=/trunk/; revision=48940
2013-04-20 02:53:57 +00:00
Guy Harris 5524d0f801 Pull tvb_init() into tvb_new(); there's no other way to get a new
tvbuff, so we might as well keep all the "here's a new tvbuff" code
together.

svn path=/trunk/; revision=48939
2013-04-19 23:39:35 +00:00
Guy Harris 36dfc6b108 Clean up a bit.
svn path=/trunk/; revision=48937
2013-04-19 18:48:16 +00:00
Guy Harris c0c15029ed Add to tvbuffs a "fragment length" field; if the tvbuff represents the
first fragment of a non-reassembled packet, and we know the length the
packet would have if it were reassembled, this field holds the length of
the fragment, and the "reported length" field shows the length the
packet would have if it were reassembled, so going past the end of the
fragment but staying within the length of the reassembled packet can be
reported as "dissection would have worked if the packet had been
reassembled" rather than "the packet is too short, so it was probably
malformed".

Add a FragmentBoundsError exception, thrown in the "dissection would
have worked if the packet had been reassembled" case.

Add a new tvb_new_subset_length_fragment() routine to create a new
subset tvb with specified fragment and reported lengths.  Use it in the
CLNP dissector.

Add some more sanity checks in the CLNP dissector.

svn path=/trunk/; revision=48917
2013-04-18 19:22:24 +00:00
Pascal Quantin 95938370bd From Ed Beroset via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8416 :
Remove C++ incompatibilities from tvbparse and tvbuff

svn path=/trunk/; revision=48025
2013-03-02 23:05:27 +00:00
Bill Meier 96a24cc79f Fix spelling/typos found using a list of commonly misspelled words.
The misspellings were mostly in comments but some were
in text strings visible to the user.


svn path=/trunk/; revision=47899
2013-02-26 04:42:26 +00:00
Guy Harris d02eea90a2 compute_offset_length(), check_offset_length_no_exception(), and
check_offset_length() are always passed the captured length and reported
length of a tvbuff; just pass a pointer to the tvbuff, instead.

Eliminate some extra blank lines.

svn path=/trunk/; revision=47868
2013-02-24 21:45:09 +00:00
Guy Harris 14b01f991c tvb_set_subset_no_exceptions() is called immediately after all calls to
tvb_new_with_subset(), and is not called anywhere other than immediately
after calls to tvb_new_with_subset(); absorb it into tvb_new_with_subset().

svn path=/trunk/; revision=47867
2013-02-24 21:30:00 +00:00
Guy Harris 370eae07ad Move some routines around, in preparation for some other code
reorganization.

svn path=/trunk/; revision=47866
2013-02-24 21:18:45 +00:00
Guy Harris 6c575002e5 Fix copy-and-pasteo.
svn path=/trunk/; revision=47769
2013-02-20 08:37:40 +00:00
Guy Harris 67e692da1c Add a tvb_new_subset_length() that takes a tvbuff, an offset in a
tvbuff, and a length from that offset, and returns a subset tvbuff
referring to that data (or throws an exception).  This does what most if
not all calls to tvb_new_subset() (other than the ones that really
should be calls to tvb_new_subset_remaining()) should be doing, i.e.
setting the reported length of the tvbuff to the specified length and
calculating the appropriate value of the captured length based on that.

We aren't using it yet, but we will....

svn path=/trunk/; revision=47768
2013-02-20 08:10:14 +00:00
Guy Harris cf1070b4b1 Swallow up tvb_set_real_data_no_exceptions() into tvb_new_real_data() -
the only caller is tvb_new_real_data().

svn path=/trunk/; revision=47757
2013-02-20 01:01:32 +00:00
Guy Harris 75168f6bf7 No more tvb_new(), so no more need for tvb_set_real_data() or
tvb_set_subset(); code should use tvb_new_real_data() and various
tvb_new_subset routines.  (Neither tvb_new() nor tvb_set_real_data() nor
tvb_set_subset() were exported in libwireshark.def, nor were they used
outside tvbuff.c; tvb_set_real_data() and tvb_set_subset() weren't even
being used *inside* tvbuff.c.)

svn path=/trunk/; revision=47753
2013-02-20 00:09:41 +00:00
Guy Harris bd7c0171a9 Make tvb_new() an internal routine to epan/tvbuff.c; we export various
routines to create new tvbuffs that do what dissectors need to do, and
those are the only routines that should be used.

svn path=/trunk/; revision=47752
2013-02-19 23:55:19 +00:00
Martin Kaiser 50945da41c check the length parameter for tvb_get_unicode_string() and
tvb_get_ephemeral_unicode_string(), throw an exception for invalid
lengths (including -1, but length==-1 does not work for other tvb string
functions either)

I believe this is the proper fix for
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8112

svn path=/trunk/; revision=46705
2012-12-22 22:35:07 +00:00
Jeff Morriss bd3a06065d Another composite-TVB fix inspired by
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8097 :

Assert out if tvb_composite_finalize() is called on a composite TVB with
no members (sub-TVBs).

svn path=/trunk/; revision=46570
2012-12-16 19:26:12 +00:00
Jeff Morriss 306821bf6e As suggested by Evan in https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8097 :
Put r46564 back in as the computation of member_length is non-trivial.

svn path=/trunk/; revision=46567
2012-12-16 18:23:10 +00:00
Jeff Morriss c6c5c3d978 A different fix for https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8097 :
Rather than asserting out when we find a zero-length TVB in a composite TVB,
assert out when a dissector adds a zero-length TVB to a composite.

svn path=/trunk/; revision=46566
2012-12-16 16:49:52 +00:00
Evan Huus 18538f6c8a DISSECTOR_ASSERT on member_length when composing a disjoint tvb in order to
avoid an infinite recursion. More robust handling of the error case in
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8097
but doesn't fix the actual bug (which is that either DHCP or BOOTP is building
an invalid tvbuff).

svn path=/trunk/; revision=46564
2012-12-16 16:21:41 +00:00
Jeff Morriss 3729335973 We always HAVE_CONFIG_H so don't bother checking whether we have it or not.
svn path=/trunk/; revision=45016
2012-09-20 01:48:30 +00:00
Jakub Zawadzki bf81b42e1e Update Free Software Foundation address.
(COPYING will be updated in next commit)

svn path=/trunk/; revision=43536
2012-06-28 22:56:06 +00:00
Jakub Zawadzki 2919ac5a5e Add some explation about buffer size.
svn path=/trunk/; revision=43266
2012-06-14 20:13:45 +00:00
Jakub Zawadzki 0711ac874f Optimize tvb_*_unicode functions.
- Allocate tmpbuf on stack. g_unichar_to_utf8[1] requires maximum 6B + 1 byte for NUL, align it to 8B.
- Use g_string_append_unichar()

[1] http://developer.gnome.org/glib/2.26/glib-Unicode-Manipulation.html#g-unichar-to-utf8

svn path=/trunk/; revision=43263
2012-06-14 19:08:19 +00:00
Gerald Combs 21b3256918 Assign some variables that scan-build was complaining about.
svn path=/trunk/; revision=42638
2012-05-15 21:56:02 +00:00
Guy Harris 1c2a67f348 Make the encoding argument uniformly guint rather than gint.
Put the code that's currently common to the ENC_ASCII and ENC_UTF_8
cases in tvb_get_ephemeral_string_enc() into tvb_get_ephemeral_string(),
and call tvb_get_ephemeral_string() in those cases.  Skip the
tvb_ensure_bytes_exist() and ensure_contiguous() calls in the ENC_UTF_16
and ENC_UCS_2 cases, as they're unnecessary there.

Update the comment for tvb_get_ephemeral_string_enc().

Make tvb_get_ephemeral_stringz_enc() handle the encodings that
tvb_get_ephemeral_string_enc() does.

svn path=/trunk/; revision=42627
2012-05-15 05:42:58 +00:00
Jakub Zawadzki 0f1a21aaa9 tvb_unicode_strsize() returns number of bytes, NOT number of UCS-2 characters.
svn path=/trunk/; revision=42622
2012-05-14 06:32:16 +00:00
Guy Harris 14b616c35d Get rid of remaining Booleans-as-encoding-arguments in
proto_tree_add_item() calls.

Add new "add_packet_field" method to the TreeItem class, taking a
protocol field (*not* a protocol), TvbRange, and encoding value as
arguments.

Add the ENC_ values to init.lua.  Make them all hex #defines so
make-init-lua.pl can easily extract them.

Export tvb_unicode_strsize() for use by Lua (and elsewhere as desired). 
Note that it handles UTF-16 and UTF-8, and fix the comment to note that
its count of hexadectets *does* include the null terminator (that's what
the code does).

svn path=/trunk/; revision=42621
2012-05-14 00:49:05 +00:00
Guy Harris 7a87d7b6a3 Add ENC_UTF_16 and ENC_UCS_2. Note that UTF-16 and UCS-2 are not the
same, and that the routines to get "Unicode" strings are really doing
UCS-2 (and not doing anything about code values that aren't valid in
UCS-2 strings).

Have tvb_get_ephemeral_string_enc() separate cases for ASCII and UTF-8,
even though they're *currently* treated the same.

For FT_UINT_STRING, treat an encoding value of TRUE as meaning
"little-endian ASCII"; pass all other encodings through to
tvb_get_ephemeral_string_enc().

svn path=/trunk/; revision=42592
2012-05-11 23:55:54 +00:00
Anders Broman b02b6a932f From Evan Huus: Use Add DISSECTOR_ASSERT_HINT() macro. https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7142
svn path=/trunk/; revision=42148
2012-04-20 05:12:20 +00:00
Jakub Zawadzki 68ec58d385 Fix some: 'cast discards qualifiers from pointer target type' warnings
- Add const qualifier
- Remove some strange casts

svn path=/trunk/; revision=42131
2012-04-18 12:35:36 +00:00
Anders Broman 5d101caa89 From Martin Kaiser: CID 525 is about tvb_new_octet_aligned(). datalen can be negative or 0 when ep_alloc0(datalen) is called. If this happens, it's because of a dissector not checking the bit_offset, I think a DISSECTOR_ASSERT() is ok for fixing this. https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7068
svn path=/trunk/; revision=42032
2012-04-12 05:36:26 +00:00
Gerald Combs 1db28ae469 Clamp a value as suggested by Mike Morrin in bug 6878.
svn path=/trunk/; revision=41968
2012-04-06 00:32:26 +00:00
Gerald Combs 8b3024e57c Make bit_offset in _tvb_get_bits64 and related functions unsigned. This
removes a potential buffer overflow and should fix a bunch of Coverity
errors mentioned in bug 6878.

We might want to do the same for no_of_bits.

svn path=/trunk/; revision=41945
2012-04-04 21:54:22 +00:00
Jakub Zawadzki 35eae45497 These buffers in tvb_uncompress() can't ovelaps, so use optimized memcpy().
svn path=/trunk/; revision=41870
2012-03-31 12:35:07 +00:00
Jakub Zawadzki 60f47ed05b Fix for bug #6480 (https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6480)
Yay, first commit since r37883 (almost 9months).

svn path=/trunk/; revision=41869
2012-03-31 12:33:10 +00:00
Bill Meier d4c21b2123 From Mike Morrin: Fix for "The previous patch had an error and was returning too many bits."
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6878

From me: Correct the indentation to match the rest of the file.


svn path=/trunk/; revision=41230
2012-02-28 20:32:42 +00:00
Guy Harris b474b4006c Initialize "value" in _tvb_get_bits64(). Clean up indentation.
svn path=/trunk/; revision=41228
2012-02-28 18:31:19 +00:00
Jörg Mayer 294e0e98f6 Fix several messages of type:
epan/tvbuff.c: In function ‘tvb_get_bits16’:
epan/tvbuff.c:1736:82: error: unused parameter ‘encoding’ [-Werror=unused-parameter]

Compilation still fails with:
epan/tvbuff.c: In function ‘_tvb_get_bits64’:
epan/tvbuff.c:1829:19: error: ‘value’ may be used uninitialized in this function [-Werror=uninitialized


svn path=/trunk/; revision=41227
2012-02-28 17:44:49 +00:00
Anders Broman 075bd9f86a From Mike Morrin:
Overhaul of tvb_get_bitsxx() functions.

https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6878

svn path=/trunk/; revision=41226
2012-02-28 16:29:07 +00:00
Alexis La Goutte 99c039e0d3 Fix some Dead Store (Dead assignement/Dead increment) Warning found by Clang
svn path=/trunk/; revision=40473
2012-01-13 16:36:07 +00:00
Bill Meier 1e89640004 (Trivial) Indentation, whitespace & formatting cleanup.
svn path=/trunk/; revision=40278
2011-12-22 18:13:18 +00:00
Bill Meier 14309d2c72 A simplified version of tvbuffs:
- Essentially no changes from current dissector de facto tvbuff usage;
- Do away with 'usage_counts' and with 'used_in' GSLists;
- Manage tvb chains via a simple doubly linked list.
- API changes:
  a. tvb_increment_usage_count() and tvb_decrement_usage_count() no
     longer exist;
  b. tvb_free_chain() can only be called for the 'top-level' (initial)
     tvb of a chain) or for a tvb not in a chain.
  c. tvb_free() now just calls tvb_free_chain() [should have no impact
     on existing  dissectors].

svn path=/trunk/; revision=40264
2011-12-21 17:39:02 +00:00
Bill Meier ed79560623 Add a comment about tvb_get_ephemeral_faked_unicode() has been replaced by tvb_get_ephemeral_unicode_string().
svn path=/trunk/; revision=39528
2011-10-23 22:02:56 +00:00
Guy Harris 330fd51e8e tvb_get_bits{16,32,64} get passed encoding values. Rename the argument
appropriately; the only valid encoding is big-endian, so we don't
actually do anything different with the argument, so as not to break
code that passed it a gboolean endian flag.

svn path=/trunk/; revision=39237
2011-10-03 06:12:11 +00:00
Anders Broman 02cba4defa Yet another bug fix from Pascal.
svn path=/trunk/; revision=39161
2011-09-26 21:06:55 +00:00
Anders Broman f54cc3fcb7 Another bug fix from Pascal.
svn path=/trunk/; revision=39155
2011-09-26 18:56:27 +00:00
Anders Broman 75b86a9cd4 From Pascal Quantin:
When building the last byte, the remaining number of bits isn't masked.

svn path=/trunk/; revision=39152
2011-09-26 17:19:54 +00:00
Anders Broman 5f76488f0a Move tvb_new_octet_aligned() to tvbuff.c and use it.
svn path=/trunk/; revision=39150
2011-09-26 15:11:14 +00:00
Gerald Combs 49b92440de More GLIB_CHECK_VERSION cleanups. Update the minimum GLib/GTK+ versions
in README.devloper. Remove g_gnuc.h since it's no longer needed. Remove
tvbuff_init(), tvbuff_cleanup(), reassemble_init(), and
reassemble_cleanup() since they were only used for older GLib versions
which didn't support GSlices. Assume we always support the "matches"
operator.

svn path=/trunk/; revision=37978
2011-07-11 20:32:19 +00:00
Guy Harris 053c583fda Add some additional routine variants that handle string encodings, and
make FT_STRING and FT_UINT_STRING handle string encodings.

Get rid of FT_EBCDIC in favor of FT_STRING with ENC_EBCDIC.

Add some URLs for DRDA.

Clean up some stuff in TN3270 and TN5250, including using ENC_ values
for proto_tree_add_item().

svn path=/trunk/; revision=37909
2011-07-05 23:59:23 +00:00
Guy Harris 338af96b2e Add a tvb_get_ephemeral_string_enc() routine that's like
tvb_get_ephemeral_string() but takes an ENC_ value for the character
encoding.  Use it in the MQ dissector to fetch strings to put, for
example, into the Info column, so we properly handle EBCDIC strings
there.

svn path=/trunk/; revision=37876
2011-07-03 17:08:25 +00:00
Guy Harris 4447b23f6b Squelch some compiler warnings.
svn path=/trunk/; revision=37685
2011-06-16 18:34:17 +00:00
Jeff Morriss f3f9f2697f Make TVBs opaque for most users.
Convert TVB_RAW_OFFSET() and TVB_GET_DS_TVB() into functions.

svn path=/trunk/; revision=37422
2011-05-27 03:06:50 +00:00
Jakub Zawadzki 7e3bbb2784 Fix tvb_get_bits_buf for LSB.
svn path=/trunk/; revision=37264
2011-05-18 21:33:05 +00:00
Jakub Zawadzki 3bb5e937d4 - Optimize tvb_get_bits_buf
- Add lsb0 (read: least significant bit is 0) parameter to tvb_get_bits_buf() 
  (not tested, might be buggy...)

svn path=/trunk/; revision=37254
2011-05-18 18:49:33 +00:00
Jakub Zawadzki e21e71e46e Add generic tvb_get_bits_buf() which accepts any no_of_bits.
svn path=/trunk/; revision=37217
2011-05-17 22:20:14 +00:00
Jakub Zawadzki 12d8f46860 Fix double free.
compr is also freed outside loop. So free it only when returning.

Might be related with bug #5908, but I don't have access to that bug ;-)

svn path=/trunk/; revision=37081
2011-05-12 16:31:42 +00:00
Anders Broman 6cef8aa872 From jakub Zawadzki:
I've fixed composite tests #0 and #2

svn path=/trunk/; revision=36440
2011-04-04 05:48:06 +00:00
Bill Meier 7f0107220d Fix various instances of "unreachable code".
svn path=/trunk/; revision=35713
2011-01-30 23:27:57 +00:00
Stephen Fisher d37c33b7e7 Mention that the fake tvb unicode functions have been superceded
svn path=/trunk/; revision=35689
2011-01-28 20:01:01 +00:00
Stephen Fisher fc7b0c019b Fix the dead initialization warnings found by clang's static analysis
("Value stored to 'xxx' during its initialization is never read")


svn path=/trunk/; revision=35598
2011-01-20 18:56:11 +00:00
Chris Maynard 116d67e164 Add tvb_get_[n|le]toh[40|48|56]() accessors. Addresses bug 5082.
svn path=/trunk/; revision=35538
2011-01-14 19:02:38 +00:00
Jeff Morriss 05400b7709 There's no need to call tvb_get_ptr() in here: just call ensure_contiguous() directly.
svn path=/trunk/; revision=35509
2011-01-12 20:25:36 +00:00
Jeff Morriss 0c4e881911 Introduce, and start using, tvb_get_const_stringz(). This function returns a
pointer to a NULL-terminated string in the TVB.  It is no safer than dissectors
which call tvb_get_strsize() and then tvb_get_ptr() but it makes it clear that
this usage of tvb_get_ptr() is safe.

This function is slightly more efficient than tvb_get_ephemeral_stringz()--but
only as long as we're not using composite TVBs.

svn path=/trunk/; revision=35493
2011-01-12 02:25:08 +00:00
Stephen Fisher 55e08f007e Introduce two new functions for Unicode (UTF-16) string handling:
tvb_get_unicode_string()
	tvb_get_ephemeral_unicode_string()

These function like their counterparts, tvb_get_string and
tvb_get_epemeral_string, for standard strings.

Also update comment on what the first such function,
tvb_get_ephemeral_unicode_stringz does regarding updating lengthp.


svn path=/trunk/; revision=35344
2011-01-03 18:29:29 +00:00
Anders Broman 735709bee6 Add tvb_bcd_dig_to_ep_str()
/*
 * Given a tvbuff, an offset into the tvbuff, and a length that starts
 * at that offset (which may be -1 for "all the way to the end of the
 * tvbuff"), fetch BCD encoded digits from a tvbuff starting from either 
 * the low or high half byte, formating the digits according to an input digit set, 
 * if NUll a default digit set of 0-9 returning "?" for overdecadic digits will be used.
 * A pointer to the EP allocated string will be returned.
 * Note a tvbuff content of 0xf is considered a 'filler' and will end the conversion.
 */

svn path=/trunk/; revision=35286
2010-12-28 12:36:26 +00:00
Stephen Fisher e9f3d27b4a Add a couple more comments to new unicode function to remind us when a
variable is counting UTF-16 characters vs. normal bytes.


svn path=/trunk/; revision=35256
2010-12-23 18:26:25 +00:00
Stephen Fisher f0029fd060 Remove comment to myself that I forgot to remove before commiting r35253
and change comments to fit within 80 column display.


svn path=/trunk/; revision=35255
2010-12-23 18:24:39 +00:00
Stephen Fisher 4f5ccc00f8 Introduce new function called tvb_get_ephemeral_unicode_stringz(), which
is a unicode (UTF-16) version of tvb_get_ephemeral_stringz().  It scans
a tvbuff for a UTF-16 string and converts it to UTF-8 upon return.


svn path=/trunk/; revision=35253
2010-12-23 17:59:34 +00:00
Anders Broman ab16d07fd3 From Vincent Helfre:
Bug in tvb_get_bits32(), The last bitshift is too large, which causes the least significant bits to be 0 all the time.

svn path=/trunk/; revision=35015
2010-11-23 17:33:57 +00:00
Jeff Morriss 0b7e2cd37e Make tvb_strncaseeql()'s size parameter be a size_t. Cast the size to int before calling ensure_contiguous_no_exception() (also in tvb_strneql()).
svn path=/trunk/; revision=34727
2010-10-30 18:53:31 +00:00
Jeff Morriss f5d3a16225 Make tvb_strneql()'s size parameter be a size_t. Remove some now-unnecessary casts.
svn path=/trunk/; revision=34725
2010-10-30 18:18:12 +00:00
Guy Harris cd67ad0047 Clean up indentation.
svn path=/trunk/; revision=33814
2010-08-16 17:19:15 +00:00
Anders Broman 63bffd3ac5 From rodebiet:
tvb_get_bits32 produces malformed_packet if no_of_bits < 25 and tvb remaining = 3
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=5080

svn path=/trunk/; revision=33811
2010-08-16 15:13:54 +00:00
Guy Harris 1b444c55fd Refer to the endianness arguments as "encoding" rather than
"representation" - we already use "representation" to refer to the text
representation of fields.

Change some routines with an endianness argument to make it a
representation argument instead; 

svn path=/trunk/; revision=32929
2010-05-24 06:06:17 +00:00
Anders Broman 1c1142fce6 From Jakub Zawadzki:
- use Glibc:s  highly optimized memchr()

svn path=/trunk/; revision=32584
2010-04-28 08:15:20 +00:00
Anders Broman 4a711cc74a From Jakub Zawadzki:
- optimize guint8_pbrk().

svn path=/trunk/; revision=32583
2010-04-28 07:58:59 +00:00
Bill Meier 6812b68eb1 From Yaniv Kaul: constify parameters
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4422

 From me: Fix a number of instances where the function prototype or
  the function definition wasn't changed so there was a mismatch 
  thus causing Windows (but not gcc) compilation errors.

svn path=/trunk/; revision=32365
2010-04-03 18:18:50 +00:00
Bill Meier d32b4c0758 Revert SVN #32360 until Windows compilation errors corrected.
svn path=/trunk/; revision=32361
2010-04-02 15:18:03 +00:00
Bill Meier 049f9eac85 From Yaniv Kaul: constify parameters
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4422

svn path=/trunk/; revision=32360
2010-04-02 14:37:49 +00:00
Anders Broman 25af78517e Make tvb_pbrk_guint8() return the found needle.
svn path=/trunk/; revision=32144
2010-03-08 20:45:13 +00:00
Bill Meier 9d663d7081 Fix various gcc -Wshadow warnings.
svn path=/trunk/; revision=31720
2010-01-28 18:45:46 +00:00
Stig Bjørlykke bb5ef1c521 parent is not unused in tvb_child_uncompress().
svn path=/trunk/; revision=31658
2010-01-25 13:54:05 +00:00
Jaap Keuter 5dcaa2bec0 Make more output parameters optional.
svn path=/trunk/; revision=31059
2009-11-23 22:02:12 +00:00
Gerasimos Dimitriadis 9b36fc784e From yy:
About GSM system information type 2quater
Modified to use newly defined tvb_get_bits() in tvbuff.c
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4219


svn path=/trunk/; revision=30962
2009-11-14 20:13:43 +00:00
Kovarththanan Rajaratnam dc265696a1 tvb_format_text() always returns a non NULL pointer so don't check return value for NULL pointer
svn path=/trunk/; revision=30821
2009-11-04 16:08:47 +00:00
Kovarththanan Rajaratnam 30cb2b9448 Add DISSECTOR_ASSERT() before dereferencing a possible NULL pointer
svn path=/trunk/; revision=30404
2009-10-08 15:01:25 +00:00
Kovarththanan Rajaratnam 7775703b1a Use g_new0() when allocating z_stream
svn path=/trunk/; revision=30277
2009-10-04 06:32:43 +00:00
Kovarththanan Rajaratnam 911b058d02 Use GLibs CLAMP(). The current inlined implementation seems to be wrong:
} else if (bufsiz > TVB_Z_MAX_BUFSIZ) {
		bufsiz = TVB_Z_MIN_BUFSIZ;
	}

This should probably have been 'bufsiz = TVB_Z_MAX_BUFSIZ;'

svn path=/trunk/; revision=30276
2009-10-04 06:28:50 +00:00
Kovarththanan Rajaratnam 19bf38ac52 Delay allocation of z_stream
svn path=/trunk/; revision=30275
2009-10-04 06:20:32 +00:00
Kovarththanan Rajaratnam 1703bfa464 g_malloc0() doesn't return NULL so remove NULL error paths
svn path=/trunk/; revision=30274
2009-10-04 06:12:31 +00:00
Kovarththanan Rajaratnam c285a1cd3a Remove 'type' formal parameter from tvb_new_with_subset()
svn path=/trunk/; revision=29988
2009-09-20 07:35:39 +00:00
Kovarththanan Rajaratnam b97cfa22fd offset_from_real_beginning() is only called with 0 as second argument, so remove the argument completely. It seems that the second argument only acts as an accumulator allowing offset_from_real_beginning() to call itself recursively. To be consistent offset_from_real_beginning() is renamed to tvb_offset_from_real_beginning().
svn path=/trunk/; revision=29844
2009-09-10 16:54:02 +00:00
Kovarththanan Rajaratnam fe6f8b92c7 Add a new function, tvb_new_subset_remaining(), which is a sligtly optimized version of tvb_new_subset(). The latter can be mapped to the former by tvb_new_subset(tvb, offset, -1 /* backing_length */, -1 /* reported_length */). We can disable some bounds checking because 'backing_length' and 'reported_length' are hardcoded to -1.
The current implementation of tvb_new_subset_remaining() only has the THROW_ON(reported_length < 1) check removed when compared to tvb_new_subset(). So there's room for improvement in this function. We should be able to disable some more (redundant) bounds checking.

svn path=/trunk/; revision=29445
2009-08-16 10:53:47 +00:00
Kovarththanan Rajaratnam c795851beb Remove unused parameters
svn path=/trunk/; revision=29444
2009-08-16 09:48:25 +00:00
Kovarththanan Rajaratnam 6cd59f3799 Remove the non-thread safe usage of 'last_tvb' variable in tvb_new_subset()
svn path=/trunk/; revision=29443
2009-08-16 09:18:17 +00:00
Kovarththanan Rajaratnam 998ee3a2e0 Make some of the check_XXX functions accept the length/reported length of the tvbuff as arguments instead the tvbuff. We'll need this feature in order to remove the non-thread usage of the 'last_tvb' variable in tvb_new_subset()
svn path=/trunk/; revision=29442
2009-08-16 08:18:17 +00:00
Kovarththanan Rajaratnam 01abc372e6 Remove a non thread-safe usage (useful when/if we ever support threading) of a static tvbuff in tvb_new_real_data(). The current version uses a static 'last_tvb' to keep track of the last allocated tvbuff. This is needed because some of the function we call can throw an exception. This patch improves this strategy by throwing an exception (if needed) before we try to allocate the tvbuff. This way we avoid a memleak _and_ we don't have to track the 'last_tvb' tvbuff.
svn path=/trunk/; revision=29441
2009-08-16 07:29:11 +00:00
Kovarththanan Rajaratnam aed905a6c9 Use the slice allocator if GLIB >= 2,10,0 as suggested by Anders Broman
svn path=/trunk/; revision=29434
2009-08-15 13:24:59 +00:00
Kovarththanan Rajaratnam 623db2e71e Add a missing DISSECTOR_ASSERT in tvb_init()
svn path=/trunk/; revision=29433
2009-08-15 12:41:24 +00:00
Kovarththanan Rajaratnam ef68d63745 Make mem chunk static
svn path=/trunk/; revision=29432
2009-08-15 12:29:25 +00:00
Kovarththanan Rajaratnam e1c5ffd553 (Trivial change) move ensure_contiguous() to reflect call hierarchy
svn path=/trunk/; revision=29382
2009-08-11 18:28:10 +00:00
Kovarththanan Rajaratnam 158827a5e7 Turn a comment in fast_ensure_contiguous() into a DISSECTOR_ASSERT() to make the implied requirement explicit.
svn path=/trunk/; revision=29381
2009-08-11 18:16:55 +00:00
Stig Bjørlykke 81c551ec59 Remove some "statement not reached" warnings.
svn path=/trunk/; revision=28691
2009-06-11 10:03:08 +00:00
Stig Bjørlykke a44cc2442d Fixed check for no_of_bits in tvb_get_bits16(), tvb_get_bits32() and
tvb_get_bits64().

svn path=/trunk/; revision=28658
2009-06-08 08:28:42 +00:00
Stig Bjørlykke d628c0a4cc Added tvb_format_stringzpad_wsp().
svn path=/trunk/; revision=28140
2009-04-24 08:08:37 +00:00
Guy Harris 8b7812db76 Reapply the change from revision 27946.
svn path=/trunk/; revision=27963
2009-04-05 17:24:06 +00:00
Gerald Combs 17ae564af8 Back out the previous change. As Guy pointed out, we might not want to
be so size_t-happy.

svn path=/trunk/; revision=27962
2009-04-05 16:26:16 +00:00
Gerald Combs 098eb5606f tvbuff.[ch]: Accept more size_t's.
packet-wcp.c: Add size_t casts.
packet-x11.c: Use string buffers.

svn path=/trunk/; revision=27959
2009-04-04 19:34:06 +00:00
Guy Harris 1f96f14083 Don't support a length of -1 meaning "to the end of the tvbuff" in
tvb_memcpy(); I changed the one tvb_memcpy() call that was explicitly
depending on that not to do so.  This is a small step towards getting
rid of the "-1 means to end of tvbuff" convention, support for which
requires us to do a bunch of extra checks where, for example, a protocol
has a 32-bit unsigned length field; it also gets rid of a warning about
comparing an unsigned value with a signed value.

svn path=/trunk/; revision=27946
2009-04-03 17:04:45 +00:00
Gerald Combs 342a836bba Make the "length" argument of the tvb_mem* functions a size_t since it's
not uncommon to pass them the result of pointer arithmetic. Add size_t
casts in other areas.

svn path=/trunk/; revision=27941
2009-04-03 15:30:38 +00:00
Anders Broman 4ba5d2f92b Add to new functions from the optimization patch:
tvb_child_uncompress()
tvb_new_child_real_data()

svn path=/trunk/; revision=27924
2009-04-01 16:22:51 +00:00
Stephen Fisher 1a71ec7c45 Introduce two new functions:
tvb_get_seasonal_string();
  tvb_get_seasonal_stringz();

.. which work the same as the ephemeral versions of the functions, but use
se_alloc() instead of ep_alloc().


svn path=/trunk/; revision=27868
2009-03-27 19:40:23 +00:00
Stig Bjørlykke 62f60df6b4 From Jakub Zawadzki (bug 3331):
g_free() is NULL safe, so we don't need check against it.

svn path=/trunk/; revision=27718
2009-03-13 22:06:48 +00:00
Jeff Morriss 73f7073540 Fix https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=2649 by adding some length checks to two while loops in tvb_uncompress()
svn path=/trunk/; revision=25677
2008-07-08 20:04:11 +00:00
Gerald Combs 8db852e950 Port over the composite tvbuff fixes from /trunk-1.0.
svn path=/trunk/; revision=25498
2008-06-20 20:33:38 +00:00
Jörg Mayer 944beafd70 Get rid of some unsued code: The warning causes a failure due to -Werror
svn path=/trunk/; revision=25028
2008-04-14 21:31:19 +00:00
Anders Broman 4073fa0deb From Michael McCartney:
patch for tvb_get_bits16 not to read past end of buffer
http://bugs.wireshark.org/bugzilla/show_bug.cgi?id=2439

svn path=/trunk/; revision=24942
2008-04-12 17:00:41 +00:00
Anders Broman 63c5c71cf8 Remove:
#ifdef NEED_G_ASCII_STRCASECMP_H
#include "g_ascii_strcasecmp.h"
#endif

svn path=/trunk/; revision=24859
2008-04-09 05:36:08 +00:00
Ashok Narayanan 7fe3f42d5a Fixed bug with tvb_get_bits64(); the mask array had one less "ff" than
it needs. This manifests itself in calls to tvb_get_bits64() and in
calls to proto_tree_add_bits_xxx() for >32 bits.



svn path=/trunk/; revision=24726
2008-03-25 18:53:17 +00:00
Stig Bjørlykke 6193d9d3c2 Add a inflateEnd() call to free up the stream in the re-init block.
svn path=/trunk/; revision=24559
2008-03-04 22:56:26 +00:00
Anders Broman 4d01fd05cb tvbuff.c - fix abug if reading last byte in tvb
Further H.264 decoding in SDP

svn path=/trunk/; revision=23847
2007-12-12 21:50:14 +00:00
Anders Broman e5f48395f1 Move the routines tvb_skip_wsp() to tvbuff.c
svn path=/trunk/; revision=23818
2007-12-09 17:41:16 +00:00
Guy Harris 9c89cdaaa3 strcasecmp(), strncasecmp(), g_strcasecmp(), and g_strncasecmp() delenda
est.  Use g_ascii_strcasecmp() and g_ascii_strncasecmp(), and supply our
own versions if they're missing from GLib (as is the case with GLib
1.x).

In the code to build the list of named fields for Diameter, don't use
g_strdown(); do our own g_ascii_-style upper-case to lower-case mapping
in the hash function and use g_ascii_strcasecmp() in the compare
function.

We do this because there is no guarantee that toupper(), tolower(), and
functions that use them will, for example, map between "I" and "i" in
all locales; in Turkish locales, for example, there are, in both
upper case and lower case, versions of "i" with and without a dot, and
the upper-case version of "i" is "I"-with-a-dot and the lower-case
version of "I" is "i"-without-a-dot.  This causes strings that should
match not to match.

This finishes fixing bug 2010 - an earlier checkin prevented the crash
(as there are other ways to produce the same crash, e.g. a bogus
dictionary.xml file), but didn't fix the case-insensitive string matching.

svn path=/trunk/; revision=23623
2007-11-27 18:52:51 +00:00
Anders Broman d24d657f75 Add {} to some IF statements.
svn path=/trunk/; revision=23468
2007-11-16 09:00:14 +00:00
Anders Broman 1143ab41b1 Apply yet another set of the optimization patches:
- Use a fast path for the most common use of tvb_get_xxx functions:
offset is >= 0 and tvb->real_data is set (this one is always true).
- match_strval() is a linear search, put the most common protocols
TCP/UDP/RDP first.
- fix gtk1 g_strlcat declaration Use g_strlcat

svn path=/trunk/; revision=23285
2007-10-27 14:44:29 +00:00
Guy Harris 0300ebc04a Get rid of unused variables.
Wrap 64-bit constants in G_GINT64_CONSTANT(), so they get the
appropriate suffix appended so the compiler knows they're 64 bits.

svn path=/trunk/; revision=21832
2007-05-19 03:45:39 +00:00
Anders Broman b688f9154a Split tvb_get_bits64 into tvb_get_bits8 tvb_get_bits16 tvb_get_bits32 and tvb_get_bits64
and use them in proto_tree_add_bits_ret_val().

svn path=/trunk/; revision=21828
2007-05-18 16:46:35 +00:00
Martin Mathieson 7510f41080 Fix proto_tree_add_bits_ret_val() (as now used by FP dissector).
Note that FP uses this function in a limited way, but this fixes problems seen.

svn path=/trunk/; revision=21727
2007-05-08 17:17:51 +00:00
Guy Harris ed652180e6 NULL is a pointer value; routines returning integral values shouldn't
return NULL.

svn path=/trunk/; revision=21613
2007-04-28 22:01:27 +00:00
Guy Harris b19c9f63e9 Make tvb_memdup(), like ep_tvb_memdup(), return a "void *".
svn path=/trunk/; revision=21610
2007-04-28 21:06:15 +00:00
Anders Broman 43bb2aea51 Add:
proto_tree_add_bits_ret_val()
tvb_get_bits()
And modify
proto_tree_add_bits() not to return a value.
little endian is not yet implemented.

svn path=/trunk/; revision=21607
2007-04-28 12:13:25 +00:00
Guy Harris 8ff20a50ce Fix definition of tvb_memcpy() to match declaration.
svn path=/trunk/; revision=21555
2007-04-24 17:12:29 +00:00
Guy Harris 6f8cee8acd "memcpy()" takes void *'s as arguments and returns a void *; have
tvb_memcpy() be similar, to avoid unnecessarily alignment warnings.

Do the same with "ep_tvb_memdup()".

svn path=/trunk/; revision=21554
2007-04-24 11:54:18 +00:00
Guy Harris adcccbcdee More const cleanup.
svn path=/trunk/; revision=21535
2007-04-23 18:18:08 +00:00
Guy Harris 56fcbf41be The "needles" argument of guint8_pbrk() needs to be const, as that's
what's passed to it.

svn path=/trunk/; revision=21531
2007-04-23 17:37:36 +00:00
Guy Harris 1bc049906a Add some GCC warnings to the standard set, and add some others to the
--enable-extra-gcc-checks set.

If we turn on -pedantic, try turning on -Wno-long-long as well, so that
it's not *so* pedantic that it rejects the 64-bit integral data types
that we explicitly require.

Constify a bunch of stuff, and make some other changes, to get rid of
warnings.

Clean up some indentation.

svn path=/trunk/; revision=21526
2007-04-23 10:59:26 +00:00
Gerald Combs 9022de04b1 Make our tvb exists before we try to dereference it. Fixes some of the
current fuzz errors.

svn path=/trunk/; revision=18665
2006-07-05 18:47:21 +00:00
Anders Broman 764e3ac167 New rutine tvb_format_text_wsp() which will change "whiite space" characters to space
before output.

svn path=/trunk/; revision=18519
2006-06-19 15:53:03 +00:00
Ronnie Sahlberg 89f022b12b name change
svn path=/trunk/; revision=18197
2006-05-21 05:12:17 +00:00
Tomas Kukosa bb39c4f7a6 add guid-utils.h to Makefile.common
remove unused variables from tvbuff.c

svn path=/trunk/; revision=17567
2006-03-10 12:57:22 +00:00
Tomas Kukosa 923855bb20 new FT_GUID handling - big/little endian supported
svn path=/trunk/; revision=17566
2006-03-10 11:58:22 +00:00
Guy Harris 6f38a35500 Add some inflateEnd() calls to free up stuff associated with a stream
before freeing the stream; bug 659 mentioned one of them, but there
appear to be others.

svn path=/trunk/; revision=16973
2006-01-07 03:36:37 +00:00
Ulf Lamping 3fd9edbf10 as tvb functions are frequently used by a lot of dissectors, use DISSECTOR_ASSERT() like instead of g_assert throughout tvbuff, so a malicious dissector won't crash Ethereal (at least at the ways we can detect it)
of course this won't catch e.g. NULL pointers, but far better than nothing ...

svn path=/trunk/; revision=15980
2005-09-23 18:27:30 +00:00
Ulf Lamping 76b09b1fee assert that tvb is not NULL
svn path=/trunk/; revision=15858
2005-09-18 20:11:54 +00:00
Guy Harris 25c4bc9379 Replace tvb_memcpy() calls that extract IPv4 addresses into a guint32,
and that extract IPv6 addresses into a "struct e_in6_addr", with
tvb_get_ipv4() and tvb_get_ipv6() calls - except for some that we
remove, by using proto_tree_add_item(), rather than replacing.

Have epan/tvbuff.h include epan/ipv6-utils.h, to define "struct
e_in6_addr" (not necessary to declare the tvbuff routines, but including
it there means "struct e_in6_addr" is guaranteed to be defined before
those declarations, so we don't get compiler complaints if we define it
*after* those declarations).

svn path=/trunk/; revision=15758
2005-09-11 21:25:37 +00:00
Guy Harris 266e1a3491 Add "tvb_get_ipv4()" and "tvb_get_ipv6()" addresses, to fetch IPv4 and
IPv6 addresses.  Use "tvb_get_ipv4()" in the WINS Replication dissector,
so that it gets the right answer on little-endian *AND* big-endian
machines.

svn path=/trunk/; revision=15753
2005-09-10 19:43:41 +00:00
Ulf Lamping 495eb1b788 snprintf -> g_snprintf
svn path=/trunk/; revision=15398
2005-08-17 23:10:28 +00:00
Ronnie Sahlberg 9599cf9e3b add new function tvb_get_ephemeral_stringz()
svn path=/trunk/; revision=15273
2005-08-10 14:25:59 +00:00
Ronnie Sahlberg b4441e6748 rename ep_tvb_fake_unicode() to tvb_get_ephemeral_faked_unicode() and update the README file.
svn path=/trunk/; revision=15271
2005-08-10 13:56:34 +00:00
Ronnie Sahlberg ec3ab9ec3e rename ep_tvb_get_string() to tvb_get_ephemeral_string() asnd update the documentation in README.developer
svn path=/trunk/; revision=15270
2005-08-10 13:41:13 +00:00
Ronnie Sahlberg 93c4543207 add an ep version of tvb_fake_unicode()
svn path=/trunk/; revision=15128
2005-07-28 08:55:11 +00:00
Luis Ontanon c5688891a1 new functions:
ep_tvb_memdup()
ep_alloc0()
ep_strsplit()

add all of the ep_ allocators to libethereal.def

svn path=/trunk/; revision=15100
2005-07-26 18:32:12 +00:00
Ronnie Sahlberg 0d385f730f add
ep_tvb_get_string
that acts the same as tvb_get_string   but the buffer returned need not be freed.



svn path=/trunk/; revision=15024
2005-07-24 01:56:01 +00:00
Gerald Combs c9bc1edd92 When trying to handle gzip-compressed data, don't seek past the end of our
compressed data buffer.  Fixes bug 288.

svn path=/trunk/; revision=14981
2005-07-21 21:40:57 +00:00
Gerald Combs 618b8887dc Use tvb_ensure_bytes_exist() in tvb_get_string() instead of throwing an
exception ourselves.  Fixes bug 130.

svn path=/trunk/; revision=14220
2005-04-28 18:07:40 +00:00
Gerald Combs 131ab36a32 In tvb_get_string(), throw an exception if our length is less than zero.
Add a message block length check to the AIM dissector.

svn path=/trunk/; revision=13955
2005-03-28 15:55:47 +00:00
Guy Harris 5474a467a2 From Chris Maynard: free up the z_stream we've allocated before failure
returns.  (The error returns shouldn't happen in practice, as the GLib
memory allocators never return a null pointer, they just abort the
program, but if we're going to be checking for failure and returning, we
should do the right thing anyway.)

svn path=/trunk/; revision=12957
2005-01-05 10:19:36 +00:00
Guy Harris a0de9d34c7 Add a "tvb_bytes_to_str_punct()" routine, which wraps
"bytes_to_str_punct()", and use it instead of extracting the bytes and
formatting them by hand.

svn path=/trunk/; revision=12876
2004-12-30 23:47:52 +00:00
Guy Harris a3f3ea6dbe From Charles Levert: in "tvb_fake_unicode()", convert non-ASCII
characters to '.'.

svn path=/trunk/; revision=12515
2004-11-12 10:26:56 +00:00
Guy Harris c68f62210f Add "tvb_get_ntoh64()" and "tvb_get_letoh64()" routines to fetch 64-bit
integers.

Make FT_INT64 and FT_UINT64 add numerical values, rather than byte-array
values, to the protocol tree, and add routines to add specified 64-bit
integer values to the protocol tree.

Use those routines in the RSVP dissector.

svn path=/trunk/; revision=11796
2004-08-22 00:31:58 +00:00
Guy Harris cb0506f41b Most developers have only 10 fingers, not 16. :-)
svn path=/trunk/; revision=11581
2004-08-02 18:58:19 +00:00
Olivier Biot c3ccccf2b6 From Kelly Byrd: fix tvb_uncompress() for GZIP encoded content.
svn path=/trunk/; revision=11579
2004-08-02 09:15:58 +00:00
Guy Harris 8a8b883450 Set the svn:eol-style property on all text files to "native", so that
they have LF at the end of the line on UN*X and CR/LF on Windows;
hopefully this means that if a CR/LF version is checked in on Windows,
the CRs will be stripped so that they show up only when checked out on
Windows, not on UN*X.

svn path=/trunk/; revision=11400
2004-07-18 00:24:25 +00:00
Olivier Biot 687f3af0f2 From Jerry Talkington: speed up tvb_uncompress() by increasing the minimal
and default uncompression buffer.

svn path=/trunk/; revision=10839
2004-05-10 22:14:07 +00:00
Olivier Biot 463597f54a Memory management of tvb_uncompress() needs tvb_set_free_cb().
svn path=/trunk/; revision=10817
2004-05-07 18:15:24 +00:00
Olivier Biot 77449b1085 From Kendy Kutzner: a char should be compared with '\0', not NULL.
svn path=/trunk/; revision=10806
2004-05-06 17:40:52 +00:00
Olivier Biot 659ac78357 From Jerry Talkington:
- Helper functions for uncompressing compressed tvbuffers.

	- Compressed content coding dissection in HTTP.

svn path=/trunk/; revision=10799
2004-05-05 06:55:09 +00:00
Guy Harris 834543d7c7 Use "tvb_format_text()" to display strings, so we handle non-printable
characters.

Some strings appear to be null-padded; add a "tvb_format_stringzpad()"
routine to handle them, so that we don't show the padding characters as
"\000".

svn path=/trunk/; revision=10461
2004-03-23 18:06:29 +00:00
Guy Harris d09c4c4eab Constify a bunch of stuff.
svn path=/trunk/; revision=10106
2004-02-19 05:19:10 +00:00
Guy Harris 87b219554e Make "tvb_strneql()" take a "gchar *" rather than a "guint8 *" as the
string argument.

Add some casts to squelch compiler warnings.

svn path=/trunk/; revision=9951
2004-02-01 21:30:17 +00:00
Jörg Mayer 38faa0f27b packet-dcerpc-afs4int.c
svn path=/trunk/; revision=9938
2004-02-01 06:49:25 +00:00
Jörg Mayer 11e10e61fd Change return type of tvb_format_text from guint8* to gchar*.
Remove now unnecessary casts in two files.

svn path=/trunk/; revision=9801
2004-01-23 09:40:38 +00:00
Guy Harris 129de02c79 In "tvb_ensure_bytes_remaining()", throw ReportedBoundsError, not
BoundsError, if the offset is just past the end of the reported data
(because we're ensuring that there actually *is* a byte there, and,
even according to the reported length, it isn't).

svn path=/trunk/; revision=9444
2003-12-24 23:28:17 +00:00
Guy Harris 821baa3d48 Have "tvb_ensure_length_remaining()" throw the appropriate exception if
there's no data remaining - its callers largely depend on it doing so.

That means that the BEEP dissector doesn't have to check for it
returning 0.

svn path=/trunk/; revision=9433
2003-12-23 21:22:00 +00:00
Ronnie Sahlberg 9c14c51834 Replace two expensive macros with a much simpler mechanism
to prevent memory leaks due to exceptions.

makes my tethereal testcase ~1% faster.

svn path=/trunk/; revision=9153
2003-12-03 10:14:34 +00:00
Ronnie Sahlberg 5ff0237060 performance update
replace tvb_raw_offset() which is essentially a simple assignment and which
is called a lot with a macro.

this makes my tethereal testcase 2-3% faster.

svn path=/trunk/; revision=9152
2003-12-03 09:50:40 +00:00
Ronnie Sahlberg bfaca0cab6 Move the definition of the tvbuff_t structure and friends to tvbuff.h
so that we can change tvb_get_ds_tvb() into a macro.

This function was a single line assignment and was called a lot.

This made tethereal ~2.5% faster in one testcase I use.

svn path=/trunk/; revision=9141
2003-12-02 10:23:18 +00:00
Guy Harris b530c88a3b "compute_offset_length()" must, if it returns FALSE, and "exception" is
non-null, set "*exception" to the appropriate exception - its callers
rely on it.

Now that it does that, there's no need for "check_offset_length()" to
check for a length of -1, as "compute_offset_length()" does so, and
therefore "check_offset_length_no_exception()" does so.

svn path=/trunk/; revision=8562
2003-09-28 21:39:53 +00:00
Gerald Combs 7704cdd149 Make tvb_find_tvb() return -1 if either tvb length is 0. Otherwise, an
assertion happens 'xxxx contains ""'.

svn path=/trunk/; revision=8450
2003-09-10 21:19:47 +00:00
Gilbert Ramirez 52338a3baf Add a "contains" operator for byte-strings, strings, and tvbuffs (protocols).
The search uses a naive approach; more work is required to add a
Boyer-Moore Search algorithm.

svn path=/trunk/; revision=8280
2003-08-27 15:23:11 +00:00
Guy Harris 663a127b5d A bufsize of 0 makes no sense in either "tvb_get_nstringz()" or
"tvb_get_nstringz0()", as it means there's no room even for the
terminating NUL; abort if "_tvb_get_nstringz()" is passed a bufsize of
0.

Don't throw an exception in "tvb_get_nstringz0()" if
"_tvb_get_nstringz()" returns 0 - that just means we have an empty
string.

svn path=/trunk/; revision=8150
2003-08-08 08:19:50 +00:00
Guy Harris ee97ce3196 Add new routines:
tvb_get_string() - takes a tvbuff, an offset, and a length as
	arguments, allocates a buffer big enough to hold a string with
	the specified number of bytes plus an added null terminator
	(i.e., length+1), copies the specified number of bytes from the
	tvbuff, at the specified offset, to that buffer and puts in a
	null terminator, and returns a pointer to that buffer (or throws
	an exception before allocating the buffer if that many bytes
	aren't available in the tvbuff);

	tvb_get_stringz() - takes a tvbuff, an offset, and a pointer to
	a "gint" as arguments, gets the size of the null-terminated
	string starting at the specified offset in the tvbuff (throwing
	an exception if the null terminator isn't found), allocates a
	buffer big enough to hold that string, copies the string to that
	buffer, and returns a pointer to that buffer and stores the
	length of the string (including the terminating null) in the
	variable pointed to by the "gint" pointer.

Replace many pieces of code allocating a buffer and copying a string
with calls to "tvb_get_string()" (for one thing, "tvb_get_string()"
doesn't require you to remember that the argument to
"tvb_get_nstringz0()" is the size of the buffer into which you're
copying the string, which might be the length of the string to be copied
*plus 1*).

Don't use fixed-length buffers for null-terminated strings (even if the
code that generates those packets has a #define to limit the length of
the string).  Use "tvb_get_stringz()", instead.

In some cases where a value is fetched but is only used to pass an
argument to a "proto_tree_add_XXX" routine, use "proto_tree_add_item()"
instead.

svn path=/trunk/; revision=7859
2003-06-12 08:33:32 +00:00
Guy Harris 6b36f382ad Fix "tvb_strneql()", "tvb_strncaseeql()", and "tvb_memeql()" not to
throw an exception if there aren't enough bytes in the tvbuff to
compare.

svn path=/trunk/; revision=7813
2003-06-09 07:27:42 +00:00
Guy Harris dd6f38957b Use "tvb_ensure_bytes_exist()" to check, in "tvb_fake_unicode()", to
make sure we have the entire string, rather than fetching the last
character.

svn path=/trunk/; revision=7783
2003-06-04 21:45:49 +00:00
Gerald Combs 7a132e5b48 More tvb_get_nstringz0() fixes. Timo Sirainen pointed out that Bad
Things can happen if we pass a zero buffer length to tvb_get_nstringz0().
Throw an exception if this happens.

In various dissectors make sure the tvb_get_nstringz0()'s buffer length
is greater than zero.

svn path=/trunk/; revision=7688
2003-05-19 03:23:12 +00:00
Gerald Combs 0b9bbbbdb6 Modify tvb_get_nstringz*() to behave more like snprintf(). Make changes
where necessary to reflect the new behavior.

svn path=/trunk/; revision=7607
2003-04-30 02:35:28 +00:00
Gerald Combs b2f936ff24 Fix several buffer and integer overflow issues discovered by Timo Sirainen.
tvbuff.c:

  Lots of existing code assumes that you can safely do the following:

    #define MAX_BUF 64
    guint8 *buf[MAX_BUF];
    ...

    tvb_get_nstringz0 (tvb, offset, MAX_BUF, buf, &bytes_copied);

  In reality, tvb_get_nstringz*() can potentially write one byte past
  "buf".  Modify _tvb_get_nstringz() not to do that.

packet-ppp.c:

  Check for a valid BAP suboption length.

packet-mount.c:

  Fix a possible integer overflow in dissect_group().

svn path=/trunk/; revision=7590
2003-04-28 04:03:26 +00:00
Guy Harris e345e5640e Rename "fake_unicode()" to "tvb_fake_unicode()" as it works on a tvbuff,
give it a byte-order argument, and move it to "epan/tvbuff.c".

Use it to handle UCS-2 strings in version 1 of the Service Location
Protocol.  In SRVLOC V1, use registered fields that are already there
for SRVLOC V2, and add some as needed.  Fix some field names.

svn path=/trunk/; revision=7186
2003-02-24 01:22:30 +00:00
Jörg Mayer 48be4e530d Removed trailing whitespaces from .h and .c files using the
winapi_cleanup tool written by Patrik Stridvall for the wine
project.

svn path=/trunk/; revision=6116
2002-08-28 20:41:00 +00:00
Jörg Mayer 3105ee542f Replace the types from sys/types.h and netinet/in.h by their glib.h
equivalents for the epan/ directory but leave winsock2.h in inet_pton.c
and inet_ntop.c for now (can't estimate the consequences).

svn path=/trunk/; revision=5928
2002-08-02 21:29:45 +00:00
Guy Harris 47b147ffd1 Add an extra argument to "tvb_find_line_end()", which specifies what it
should do if it doesn't find an EOL; if FALSE, it behaves as before,
returning values that treat the line as ending at the end of the tvbuff,
and if TRUE, it returns -1, so its caller can do segment reassembly
until it gets the EOL.

Add an option to the SMTP dissector to do segment reassembly, and do
segment reassembly of the first line.

svn path=/trunk/; revision=5891
2002-07-17 06:55:29 +00:00
Guy Harris b6e941027f Add a "tvb_ensure_bytes_exist()", which is like "tvb_bytes_exist()" only
it throws the appropriate exception if the bytes don't exist.  Use it in
the GIOP and ASN.1 code to check whether the bytes to be copied to a
buffer exist before allocating the buffer.

Make "check_offset_length_no_exception()" check for an overflow, so that
it can be used in "tvb_ensure_bytes_exist()" and do all the checking
that the code "tvb_ensure_bytes_exist()" replaces did.

Make "get_CDR_wchar()" return a "gint", so that if the length octet it
fetched has a value between 128 and 255, the length can be returned
correctly.

Fix some comments not to specify the exception thrown by various
routines that can throw various exceptions.

svn path=/trunk/; revision=5453
2002-05-13 01:24:47 +00:00