Commit Graph

422 Commits

Author SHA1 Message Date
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
Guy Harris 33e80cec64 Have "tvb_ensure_length_remaining()" directly call
"compute_offset_length()", and throw the exception it returns, rather
than calling "tvb_length_remaining()" and throw BoundsError if it
returns -1; this allows us to add additional exceptions without having
to change "tvb_ensure_length_remaining()".

Make "_tvb_get_nstringz()" static, as it's not used outside "tvbuff.c".

svn path=/trunk/; revision=5397
2002-05-05 21:07:52 +00:00
Guy Harris d612dab6df Make "tvb_ensure_length_remaining()" return a "guint" - it can't return
a negative value.

Use "tvb_ensure_length_remaining()" in "tcp_dissect_pdus()", rather than
checking the return value of "tvb_length_remaining()" ourselves, and
make various variables and parameters in it "guint" as appropriate.

svn path=/trunk/; revision=5396
2002-05-05 00:57:59 +00:00
Guy Harris ed02576048 Use "gfloat" and "gdouble", rather than "float" and "double", as the
return types of the tvbuff accessors for floating-point types, to more
closely match the tvbuff accessors for integral types.

Fix an error in the code for fetching doubles on VAXes, and get rid of
unused union members on VAXes.

svn path=/trunk/; revision=5245
2002-04-24 21:53:05 +00:00
Guy Harris 7d96eec76b Use Ashok's IEEE-float-to-long code as the basis for
IEEE-float-to-native-float code, and use that as the basis for
IEEE-double-to-native-double code.  Use that code on VAXes.

Eliminate "ieee-float.h", as we no longer use it; instead, we use the
tvbuff routines for extracting IEEE floating-point numbers.

svn path=/trunk/; revision=5243
2002-04-24 21:19:38 +00:00
Guy Harris 661056aac4 Add (untested) routines to fetch IEEE single-precision and
double-precision floating-point numbers, in big-endian and little-endian
format (hopefully there aren't any middle-endian formats; if there are,
we'll have to add them), from a tvbuff, and to return floats (for
single-precision) and doubles (for double-precision).

svn path=/trunk/; revision=5147
2002-04-12 23:25:24 +00:00
Gilbert Ramirez 6aad6e40b8 tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.

tvb_get_nstringz() and tvb_get_nstringz0() were both modified.

The FT_STRINGZ case in proto_tree_add_item() is made simpler.

During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.

svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
Guy Harris 6a21dc7e44 Don't give tvbuffs names; instead, give data sources names, where a
"data source" has a name and a top-level tvbuff, and frames can have a
list of data sources associated with them.

Use the tvbuff pointer to determine which data source is the data source
for a given field; this means we don't have to worry about multiple data
sources with the same name - the only thing the name does is label the
notebook tab for the display of the data source, and label the hex dump
of the data source in print/Tethereal output.

Clean up a bunch of things discovered in the process of doing the above.

svn path=/trunk/; revision=4749
2002-02-18 01:08:44 +00:00
Guy Harris 6f1b47d6c5 Squelch a GCC warning.
svn path=/trunk/; revision=4658
2002-02-01 07:03:32 +00:00
Gilbert Ramirez bd4a9c13eb Provide tvb_ensure_length_remaining(), which is like
tvb_length_remaining() except that it throws BoundsError if 'offset'
is out-of-bounds.

Allow a length argument of -1 for FT_STRING and FT_BYTES fields
in proto_tree_add_item().

Change some dissectors to either use -1 for the length argument in
calls to proto_tree_add_item(), or call tvb_ensure_length_remaining()
instead of tvb_length_remaining(), or to check the return-value
of tvb_length_remaining(). Changes to more dissectors are necessary,
but will follow later.

svn path=/trunk/; revision=4656
2002-02-01 04:34:17 +00:00
Gilbert Ramirez a2251afaff Throw a BoundsError if a length parameter in a tvbuff-accessor is < -1.
svn path=/trunk/; revision=4474
2002-01-04 06:45:14 +00:00
Guy Harris 0d7f3e614f Get rid of "tvb_compat()"; it's no longer needed (the one remaining call
to it returns data that's no longer used).

svn path=/trunk/; revision=4237
2001-11-20 22:46:12 +00:00
Gilbert Ramirez f14a6b8b91 Hopefully the last time I have to change my e-mail address.
svn path=/trunk/; revision=4199
2001-11-13 23:55:44 +00:00
Guy Harris f62a97cf2d TVBUFF_SUBSET tvbuffs share a "ds_name" with the parent tvbuff, so their
"ds_name"s shouldn't be freed when the tvbuff is freed.  (Thanks and a
tip of the Hatlo hat to the FreeBSD memory allocator for complaining
about multiple frees of the same string.)

svn path=/trunk/; revision=4136
2001-11-03 03:49:34 +00:00
Guy Harris ba06fa6490 More indentation fixes.
svn path=/trunk/; revision=4135
2001-11-03 03:41:35 +00:00
Guy Harris 6d24afcb1f Fix the indentation.
svn path=/trunk/; revision=4129
2001-11-03 00:19:26 +00:00
Gilbert Ramirez 920b294065 Fix leak of ds_name. Thanks to Sirop Erable <matrix_ottawa@yahoo.ca>
svn path=/trunk/; revision=4128
2001-11-02 21:39:34 +00:00
Guy Harris 62d224011d Stop using "tvb_get_ntohll()" and "%llX" in the BOOTP dissector, as the
former depends on having "guint64" and the latter depends on
"%ll[douxX]" being what's used to print 64-bit integers, and there are
platforms on which Etheeal runs that don't have "guint64" or that don't
use "%ll[douxX]" to print 64-bit integers.

Get rid of the routines to extract 64-bit integers into "gint64"s and
"guint64"s, as per Ronnie Sahlberg's suggestion, to discourage people
from writing code that won't work on all platforms; they should be using
FT_UINT64, or the routines in "int-64bit.c", instead.

svn path=/trunk/; revision=4102
2001-10-29 21:56:50 +00:00
Gilbert Ramirez 038da8730a Fix some signed/unsigned comparison warnings. In the case of tvbuff.h,
there were 2 functions which accepted 'maxlength' == -1, but the function
prototypes had maxlength as a guint --- fixed.

svn path=/trunk/; revision=4087
2001-10-26 17:29:12 +00:00
Guy Harris db5e1b8c85 Tvbuffify the DNS, NBNS, NBDS, and NBSS dissectors.
Add a "tvb_memeql()" routine, for doing "memcmp()"-style equality
comparisons.

svn path=/trunk/; revision=3631
2001-07-02 07:11:40 +00:00
Guy Harris cce642c0f7 Fix a comment, and update Gerald's e-mail address.
svn path=/trunk/; revision=3471
2001-05-27 21:34:05 +00:00
Jeff Foster 395b68ea19 Changes required to support multiple named data sources.
Tvbuffers changed to added the data source name,
GUI and printing code changed to support these changes
and display the multiple hex views.

svn path=/trunk/; revision=3165
2001-03-23 14:44:04 +00:00
Gilbert Ramirez 5664e5887f Make tvb_get_ptr() return 'const guint8*', and clean up all the
usages of tvb_get_ptr(). packet-ieee80211.c still has one bad usage,
in which it *does* modify the tvbuff's data.

svn path=/trunk/; revision=3128
2001-03-13 21:34:28 +00:00
Guy Harris 11b24c6094 Tvbuffify the RIP and OSPF dissectors.
Change them to use facilities in Ethereal that were probably not present
when they were originally written, e.g. routines to fetch 24-bit
integers and to dump a bunch of raw bytes in hex.

Redo them to extract data from the packet as they dissect it, rather
than extracting an entire data structure at once; that way, it may be
able to dissect a structure not all of which is in the packet.

Dissect a bit more of the type-of-service metrics etc. in OSPF packets.

Make "tvb_length_remaining()" return a "gint", not a "guint"; it returns
-1 if the offset is past the end of the tvbuff.

Add a "tvb_reported_length_remaining()" routine, similar to
"tvb_length_remaining()".  Use it instead of just subtracting an offset
from "tvb_reported_length()".

svn path=/trunk/; revision=2787
2000-12-27 12:48:27 +00:00
Guy Harris d46aa3d576 Add a new "tvb_strsize()" routine, which finds the size of a
NUL-terminated string, starting at a given offset.  The size includes
the terminating NUL.  If it doesn't find the terminating NUL, it throws
the appropriate exception, as either there's no terminating NUL in the
packet or there is but it's past the end of the captured data in the
packet.

Use that routine in the TFTP dissector.  As it throws an exception if
the string isn't NUL-terminated, we can just use "%s" to print option
strings; we don't need to use "%.*s" with a string length.

svn path=/trunk/; revision=2783
2000-12-25 23:48:16 +00:00
Guy Harris 50f6a061a7 In "tvb_find_guint8()" and "tvb_pbrk_guint8()", correctly set the limit
of the search if the caller-supplied limit goes past the end of the
tvbuff - the limit should just be what remains in the tvbuff after the
specified starting offset.

In "tvb_find_line_end_unquoted()", after searching for the next
interesting character, check the value we got back from that search, in
"char_offset", not whatever happens to be in "cur_offset", to see if we
found a character.

svn path=/trunk/; revision=2719
2000-11-30 06:11:32 +00:00
Gilbert Ramirez a0729a25dd In tvb_set_reported_length(), don't assert on
reported_length <= tvb->reported_length, but throw a ReportedBoundsError
if that condition is not met.

svn path=/trunk/; revision=2718
2000-11-30 03:24:16 +00:00
Guy Harris c8196a1d1c Tvbuffify the IP, ICMP, TCP, UDP, OSI CLNP, OSI COTP, OSI CLTP, and OSI
ESIS dissectors.

Register the IP dissector and have dissectors that call it directly
(rather than through a port table) call it through a handle.

Add a routine "tvb_set_reported_length()" which a dissector can use if
it was handed a tvbuff that contains more data than is actually in its
part of the packet - for example, handing a padded Ethernet frame to IP;
the routine sets the reported length of the tvbuff (and also adjusts the
actual length, as appropriate).  Then use it in IP.

Given that, "ethertype()" can determine how much of the Ethernet frame
was actually part of an IP datagram (and can do the same for other
protocols under Ethernet that use "tvb_set_reported_length()"; have it
return the actual length, and have "dissect_eth()" and "dissect_vlan()"
use that to mark trailer data in Ethernet II frames as well as in 802.3
frames.

svn path=/trunk/; revision=2658
2000-11-18 10:38:33 +00:00
Gilbert Ramirez 29a2973984 Add tvb_set_child_real_data_tvbuff(), which allows you to tell the
tvbuff routines that a particular TVBUFF_REAL_DATA tvbuff is a "child"
of another tvbuff. This link is utilized during a tvb_free_chain(), so that
the child is freed when no longer necessary.

svn path=/trunk/; revision=2642
2000-11-14 04:33:34 +00:00
Guy Harris 99c98f9e74 Move "bytes_to_str()" to "strutil.c" from "packet.c" - it's just a
string formatter, like "format_text()", and, as "tvbuff.c" now calls it
(*vide infra*), we don't want to have to make "tvbuff.c" drag "packet.h"
in just to declare "bytes_to_str()".  It's now declared in "strutil.h",
so include it in modules that use "bytes_to_str()" and weren't already
including it.

Add a "tvb_bytes_to_str()" wrapper that calls "tvb_get_ptr()" to get a
pointer to a chunk of N bytes at a given offset in a tvbuff and then
hands that chunk to "bytes_to_str()".  Convert the code that was doing
that to use "tvb_bytes_to_str()" instead (which caught what I suspect is
a bug in the Q.2931 dissector, where it was handing an offset of 0 to
"tvb_get_ptr()" - a cut-and-pasteo, I think).

Tvbuffify the ARP dissector.

svn path=/trunk/; revision=2634
2000-11-13 07:19:37 +00:00
Guy Harris f8934eb9e7 Make "tvb_find_line_end()" and "tvb_find_line_end_unquoted()" treat CR
by itself as a line ending, as well as treating CR LF and LF as line
endings.

Tweak the Telnet dissector to treat LF and CR NUL as line endings, but
not to treat CR by itself as a line ending (that's not exactly what the
NVT specification in the Telnet RFC specifies, but the resulting output
may be a bit more readable that way).

svn path=/trunk/; revision=2613
2000-11-12 00:59:09 +00:00
Guy Harris b9d2dd7151 Make the string-to-compare-with arguments to "tvb_strneql()" and
"tvb_strncaseeql()" "const guint8 *", so that you can pass them pointers
to "const".

svn path=/trunk/; revision=2611
2000-11-11 19:55:48 +00:00
Guy Harris b63646ecc0 Allow "tvb_find_guint8()", "tvb_pbrk_guint8()", and "tvb_strnlen()" to
take -1 as a "maxlength" value, meaning "to the end of the tvbuff".

svn path=/trunk/; revision=2598
2000-11-10 09:15:57 +00:00
Guy Harris 07eb30403d Tvbuffify the SAP and SDP dissectors.
Add "tvb_find_line_end_unquoted()" for the benefit of the SDP dissector;
get rid of "find_line_end_unquoted()" as nobody uses it any more.

Add "tvb_pbrk_guint8()" for the benefit of
"tvb_find_line_end_unquoted()"; it searches for any of a number of
characters, unlike "tvb_find_guint8()" which searches for only one.

svn path=/trunk/; revision=2595
2000-11-10 06:50:37 +00:00
Guy Harris 01a890cf95 Tvbuffify the HTTP, NNTP, RSH, RTSP, and Telnet dissectors.
Add "tvb_find_line_end()", to find a CR and/or LF-terminated line in a
tvbuff and return its length and the offset of the character after the
line end, for the use of those dissectors.

Add "tvb_strncaseeql()", which is like "tvb_strneql()" except that it
does a case-insensitive comparison.

svn path=/trunk/; revision=2590
2000-11-09 10:56:33 +00:00
Guy Harris 1a793d05ee Patch from Heikki Vatiainen to make "tvb_strnlen()" return the length of
the string rather than the offset of the end of the string, plus a patch
to "tvb_get_nstringz()" to treat the return value of "tvb_strnlen()" as
a length rather than an end offset.

svn path=/trunk/; revision=2502
2000-10-17 08:50:57 +00:00
Gilbert Ramirez 83ec54675c First step in moving core Ethereal routines to libepan.
svn path=/trunk/; revision=2458
2000-09-27 04:55:05 +00:00