Commit Graph

439 Commits

Author SHA1 Message Date
Peter Wu d80acae40d tvbuff: make tvb_bytes_exist fail with negative values
tvb_generic_clone_offset_len uses tvb_bytes_exist to check that the
requested tvb data is actually available. It did not expect negative
values, that would result in an overly large memory allocation.

Bug: 14678
Change-Id: Ie80095a381e55ca5dbbd5c9d835243549d0b212e
Link: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7179
Reviewed-on: https://code.wireshark.org/review/27526
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-05-14 13:07:23 +00:00
Martin Mathieson d55499ed74 More 'abs_offset' initialisation needed for gcc 4.8.5 (Leap 42.3)
Change-Id: I1f2b797ade7d92596b5b42469e3161b6e373830b
Reviewed-on: https://code.wireshark.org/review/27070
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-04-21 22:40:32 +00:00
Dario Lombardo 1a9f3b8f6d tvbuff: fix compilation with gcc-4.
../epan/tvbuff.c: In function 'tvb_new_octet_aligned':
../epan/tvbuff.c:274:26: error: 'abs_offset' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   *rem_len = tvb->length - *offset_ptr;
                          ^
../epan/tvbuff.c:486:8: note: 'abs_offset' was declared here
  guint abs_offset, rem_length;
        ^
../epan/tvbuff.c: In function 'tvb_find_line_end':
../epan/tvbuff.c:274:26: error: 'abs_offset' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   *rem_len = tvb->length - *offset_ptr;
                          ^
../epan/tvbuff.c:486:8: note: 'abs_offset' was declared here
  guint abs_offset, rem_length;
        ^
../epan/tvbuff.c: In function 'tvb_find_line_end_unquoted':
../epan/tvbuff.c:274:26: error: 'abs_offset' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   *rem_len = tvb->length - *offset_ptr;
                          ^
../epan/tvbuff.c:486:8: note: 'abs_offset' was declared here
  guint abs_offset, rem_length;

Change-Id: Iba9fe31ac5fcf604d65bbf3bceef0c09004c1b6c
Reviewed-on: https://code.wireshark.org/review/27050
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-04-20 10:48:26 +00:00
Guy Harris 0a130c5756 Handle subset tvbuffs where the length goes past the end of the parent.
Add a "contained length" to tvbuffs.  For non-subset tvbuffs, that's the
same as the reported length.  For a subset tvbuff, that's the amount of
the reported data that was actually present in the "contained data" of
the parent tvbuff.

This is unaffected by the *captured* length of any tvbuff; that differs
from the contained length only if the capture was cut short by a
snapshot length.

If a reference is within the reported data, but not within the contained
data, a ContainedBoundsError exception is thrown.  This exception
represents a protocol error, rather than a reference past the captured
data in the packet; we treat it as such.

Change-Id: Ide87f81238eaeb89b3093f54a87bf7f715485af5
Reviewed-on: https://code.wireshark.org/review/27039
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-04-20 03:18:47 +00:00
Guy Harris c7970d9356 Add, and use, "fetch signed value" for lengths < 40 bits.
Add 8-bit, 16-bit, 24-bit, and 32-bit "fetch signed value" routines, and
use them rather than casting the result of the 8/16/24/32-bit "fetch
unsigned value" routines to a signed type (which, BTW, isn't sufficient
for 24-bit values, so this appears to fix a bug
in epan/dissectors/packet-zbee-zcl.c).

Use numbers rather than sizeof()s in various tvb_get_ routines.

Change-Id: I0e48a57fac9f70fe42de815c3fa915f1592548bd
Reviewed-on: https://code.wireshark.org/review/26844
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-04-10 14:55:45 +00:00
Gerald Combs 246f0bc012 Get rid of TestBigEndian and AC_C_BIGENDIAN.
Get rid of CMake's TestBigEndian and Autotools' AC_C_BIGENDIAN checks in
favor of G_BYTE_ORDER. We use G_BYTE_ORDER elsewhere and TestBigEndian
is noticeably slow on Windows.

Change-Id: Idc1326294db9cbee8f6b6b11c2028fc4d19acbf0
Reviewed-on: https://code.wireshark.org/review/26462
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-03-13 19:09:36 +00:00
Dario Lombardo 55c68ee69c epan: use SPDX indentifiers.
Skipping dissectors dir for now.

Change-Id: I717b66bfbc7cc81b83f8c2cbc011fcad643796aa
Reviewed-on: https://code.wireshark.org/review/25694
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08 19:29:45 +00:00
Alexis La Goutte 0bde3e96f0 Add ENC_VARINT_QUIC
Used to support variable length in QUIC protocol

Bug: 13881
Change-Id: Ia274b1530152376c5fb4e364fc4cf5ab246be1b3
Reviewed-on: https://code.wireshark.org/review/24990
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Craig Jackson <cejackson51@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-01-02 05:29:39 +00:00
Guy Harris 458c3c026e Add a ws_in6_addr typedef for struct e_in6_addr.
That allows a parallel typedef of ws_in4_addr for guint32.

Change-Id: I03b230247065e0e3840eb87635315a8e523ef562
Reviewed-on: https://code.wireshark.org/review/24073
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-10-26 08:50:34 +00:00
Michael Mann d8d60b4980 Add ENC_VARINT_PROTOBUF
Encoding of integer datatypes of Protocol buffers
https://developers.google.cn/protocol-buffers/docs/encoding

Change-Id: I9f6d65ddca099c15c0634984e9394131f98d35a9
Reviewed-on: https://code.wireshark.org/review/23813
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-10-09 11:31:19 +00:00
Martin Kaiser 9d5f172875 simplify the description of tvb_memeql()
Make the description simpler than the code (hopefully).

Change-Id: Iaede1a6eb18e25e379b719f9b66ecbef0c00ea63
Reviewed-on: https://code.wireshark.org/review/20956
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-04-07 01:28:47 +00:00
Michael Mann 51a3014225 format_text_wmem -> format_text
All cases of the "original" format_text have been handled to add the
proper wmem allocator scope.  Remove the "original" format_text
and replace it with one that has a wmem allocator as a parameter.

Change-Id: I278b93bcb4a17ff396413b75cd332f5fc2666719
Reviewed-on: https://code.wireshark.org/review/19884
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-01-31 17:08:47 +00:00
Michael Mann cc479321c3 Have tvb_format_text use wmem_packet_scope() memory.
It's only use is in dissectors or other tree creation APIs (where
packet scope is valid), so have it use format_text_wmem with
wmem_packet_scope().

Change-Id: I1f34e284a870c9844c6b27f4ae08a1e7efe54098
Reviewed-on: https://code.wireshark.org/review/19883
Reviewed-by: Michael Mann <mmann78@netscape.net>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-01-31 06:34:40 +00:00
Michael Mann ad5cb2eb72 Have tvb_format_stringzpad use wmem_packet_scope() memory.
It's only use is in dissectors, so have it use
format_text_wmem with wmem_packet_scope().

Change-Id: I22121324fd47aee32174b65104458ad2ef329bd7
Reviewed-on: https://code.wireshark.org/review/19856
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-01-31 02:28:01 +00:00
Michael Mann f789c91a5e Have format_text_wsp use wmem allocated memory.
format_text_wsp is fed into by tvb_format_text_wsp and tvb_format_stringzpad_wsp
so those functions need to add a wmem allocated parameter as well.
Most of the changes came from tvb_format_text_wsp and tvb_format_stringzpad_wsp
being changed more so than format_text_wsp.

Change-Id: I52214ca107016f0e96371a9a8430aa89336f91d7
Reviewed-on: https://code.wireshark.org/review/19851
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-01-30 02:25:45 +00:00
Guy Harris c303679d99 Decode TBCD strings in GSM MAP as per the GSM MAP spec.
Hex digits 0xa through 0xe are '*', '#', 'a', 'b', and 'c',
respectively.

Constify the dgt_set_t argument to tvb_bcd_dig_to_wmem_packet_str(),
while we're at it.

Bug: 13316
Change-Id: I7586f35d23fd262453779d99946e7ccad4b6ffab
Reviewed-on: https://code.wireshark.org/review/19620
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-01-13 07:16:30 +00:00
Guy Harris 7cd6906056 Rename tvb_new_subset() to tvb_new_subset_length_caplen().
This emphasizes that there is no such thing as *the* routine to
construct a subset tvbuff; you need to choose one of
tvb_new_subset_remaining() (if you want a new tvbuff that contains
everything past a certain point in an existing tvbuff),
tvb_new_subset_length() (if you want a subset that contains everything
past a certain point, for some number of bytes, in an existing tvbuff),
and tvb_new_subset_length_caplen() (for all other cases).

Many of the calls to tvb_new_subset_length_caplen() should really be
calling one of the other routines; that's the next step.  (This also
makes it easier to find the calls that need fixing.)

Change-Id: Ieb3d676d8cda535451c119487d7cd3b559221f2b
Reviewed-on: https://code.wireshark.org/review/19597
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-01-10 06:19:37 +00:00
Guy Harris b604fff136 Rename non-EBCDIC-specific routines.
Those routines can handle any single-byte character set whose characters
map to characters in the Basic Multilingual Plane; it could be used for
extended ASCII, but we have another routine for that, mapping only
characters with code points > 0x7f, so we just say "nonascii" rather
than "ebcdic".

Change-Id: I3d55b5d58e3e7ab08f3dfbfdb57a0301a30e71d4
Reviewed-on: https://code.wireshark.org/review/19214
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-12-12 08:20:22 +00:00
Guy Harris 4d47c9a841 Fix handling of EBCDIC string fields.
Have a routine that takes a 256-element translation table and uses it to
map various flavors of EBCDIC to Unicode.  Have separate translation
tables for "common" EBCDIC (everything that's the same in all EBCDIC
code pages that include the original EBCDIC characters) and EBCDIC code
page 037.  Add ENC_EBCDIC_CP037 for code page 037.

Change-Id: Ia882b3c0abef9e30eb54cd47396e6fa0d6342044
Reviewed-on: https://code.wireshark.org/review/19212
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-12-12 05:49:50 +00:00
AndersBroman e723a899c0 [tvbuff] Fix tvb_find_guint16() searched_bytes is from
start_offset(offset) and the while loop should be on searched_bytes.

Change-Id: I62343f7cb04f9110f773ba1ada8dbcbfbd262861
Reviewed-on: https://code.wireshark.org/review/18741
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-11-11 16:05:52 +00:00
Pascal Quantin 321b756dc4 Add T.61 character set support
Bug: 13032
Change-Id: I6bf2cc2c43a6262d899a304df6576d9831115966
Reviewed-on: https://code.wireshark.org/review/18350
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-10-22 03:16:11 +00:00
Guy Harris 10ca4c7527 More checks for localtime() and gmtime() returning NULL.
And some comments in the case where we're converting the result of
time() - if your machine's idea of time predates January 1, 1970,
00:00:00 UTC, it'll crash on Windows, but that's not a case where a
*file* can cause the problem due either to a bad file time stamp or bad
time stamps in the file.

Change-Id: I837a438e4b875dd8c4f3ec2137df7a16ee4e9498
Reviewed-on: https://code.wireshark.org/review/18369
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-10-22 02:27:32 +00:00
Francesco Fondelli b682bbd6ee add tvb_find_guint16() utility
Change-Id: I75c0165948325c2e50918706d8a821411761727b
Signed-off-by: Francesco Fondelli <francesco.fondelli@gmail.com>
Reviewed-on: https://code.wireshark.org/review/17734
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-10-08 03:21:44 +00:00
Martin Kaiser d1ae5bc961 clean up some comments in tvb_find_line_end()
Change-Id: I9025b479b31e3cc6f8108a163bf00d81008fd737
Reviewed-on: https://code.wireshark.org/review/15632
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-06-02 08:31:01 +00:00
Jaap Keuter eb75ec1824 Prevent inproper use of negative value
Coverity rightfully complains about inproper use of negative value.
maxlength special value '-1' should be handled appropriately.

Change-Id: Ie1818121e39fa668094d012980016444ca868e6e
Reviewed-on: https://code.wireshark.org/review/13978
Reviewed-by: João Valverde <j@v6e.pt>
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-02-19 03:23:07 +00:00
João Valverde b87a5af633 Fix build [-Werror=maybe-uninitialized]
Found building with GCC 5.3.0 and CFLAGS="-g -Og".

Change-Id: I5bc29b6e91cc98332a513c9d03b02d2f6906608d
Reviewed-on: https://code.wireshark.org/review/13362
Reviewed-by: João Valverde <j@v6e.pt>
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
2016-01-17 19:12:45 +00:00
João Valverde cbc36cbd97 Remove constness from bytestring_to_str() [-Wcast-qual]
Change-Id: I7f942787dfdc4f76dd0ad5111d1eb528b20f0ba9
Reviewed-on: https://code.wireshark.org/review/13011
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: João Valverde <j@v6e.pt>
2016-01-07 22:40:30 +00:00
Guy Harris 6655dd93e5 Only check for the last nibble being 0x0f.
That's what my_dgt_tbcd_unpack() did; do the same thing here.

Change-Id: Ia68c6ba652c748bd2661fd6eda736e880f414dc5
Reviewed-on: https://code.wireshark.org/review/12359
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-12-02 01:47:55 +00:00
AndersBroman 6e87802ec0 tvb_new_octet_aligned() should return both the captured and reported
length set to datalen in the returned tvb.

Change-Id: Ie6649a285a9fa4a0564e29ce18ec9459b8da2541
Reviewed-on: https://code.wireshark.org/review/9861
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-08-04 08:54:14 +00:00
Guy Harris bfb4327291 Remove tvb_ from the names of wsutil mempbrk routines.
Routines that don't take a tvbuff as an argument shouldn't have tvb_ in
the name.

Change-Id: I3550256551e30b3f329cbbfca71ef27c727d29c0
Reviewed-on: https://code.wireshark.org/review/7302
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-02-21 20:39:25 +00:00
Pascal Quantin bdcac172ea Fix crash at startup in SSE4.2 code when running a 32 bits Windows build
There is no guarantee that a g_malloc'ed memory block will be aligned on a 128 bits boundary
Instead use a static variable definition (at the cost of exposing the HAVE_SSE4_2 compilation flag in ws_mempbrk.h)

Change-Id: I661bf479a9d458d64c96bafc940c519d29a4780b
Reviewed-on: https://code.wireshark.org/review/7070
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
2015-02-12 16:37:55 +00:00
Hadriel Kaplan a837570d02 Combine SSE and pre-compiled patterns for faster pbrk
This combines the SSE4.2 instructions usage, with pre-compiled
pattern searching usage, for a faster pbrk search method.

Testing against large files of HTTP and SIP, there is about
a 5% performance improvement by using pre-"compiled" patterns
for guint8_pbrk() instead of passing it the search string and
having it build the match array every time.
Similar to regular expressions, "compiling" the pattern match array
in advance only once and using the "compiled" patterns for
the searches is faster than compiling it every time.

Change-Id: Ifcbc14a6c93f32d15663a10d974bacdca5119a8e
Ping-Bug: 10798
Reviewed-on: https://code.wireshark.org/review/6990
Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-02-11 09:14:50 +00:00
Michael Mann 64a7bac641 tvb_bytes_to_ep_str -> tvb_bytes_to_str
Change-Id: I79c613cbdd8dc939dd4c29ebc477fb6eefd5bfc4
Reviewed-on: https://code.wireshark.org/review/6371
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-01-07 18:16:23 +00:00
Michael Mann 9cfe67fde6 tvb_bytes_to_ep_str_punct -> tvb_bytes_to_str_punct
Also change bytestring_to_str to match bytes_to_ep_str_punct functionality (limiting byte string size)

Change-Id: Idb958c7f0c203d103629469302b81fa922714f7e
Reviewed-on: https://code.wireshark.org/review/6369
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-01-07 18:05:35 +00:00
Hadriel Kaplan fac8356610 Make all Lua code use wmem not emem
Changed all remaining code in wslua that was using emem, to use wmem or
simpler methods.

Bug: 9927
Change-Id: I3d19a770e0fd77d996bdb6b61a76a722cc2bcd55
Reviewed-on: https://code.wireshark.org/review/6109
Petri-Dish: Michael Mann <mmann78@netscape.net>
Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com>
Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-01-04 21:02:38 +00:00
Evan Huus 55c385e610 tvb: implement endianness-paramterized getters
e.g. tvb_get_guint16(tvb, offset, ENC_LITTLE_ENDIAN)

Change-Id: Iea02fd59b13678aca741d028fb1f66f334447498
Reviewed-on: https://code.wireshark.org/review/6191
Reviewed-by: Michael Mann <mmann78@netscape.net>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Evan Huus <eapache@gmail.com>
2015-01-02 04:07:19 +00:00
Evan Huus 91d1c3c5ec reassembly: fix when fragment cut off by snapshot
Also add an assertion to tvb_generic_clone_offset_len so that it throws an
error *before* allocating memory, as otherwise that memory is leaked.

Bug: 10474
Change-Id: I5036cefac16841914a59670c64979cf599bf7969
Reviewed-on: https://code.wireshark.org/review/4234
Petri-Dish: Evan Huus <eapache@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Evan Huus <eapache@gmail.com>
2014-09-25 12:41:36 +00:00
Guy Harris 66318ad5eb Don't assert out on tvb_memcpy() with a null data pointer if the length is 0.
If the length is 0, there's nothing to copy, so it doesn't matter if
there's no data to copy from.  This fixes problems caused by allocating
a zero-length buffer and using that as the data for a tvbuff; the
allocation returns null, so the data pointer is null.

Change-Id: I8037ae4b96d30e90a716852bb7e22d3980444f83
Reviewed-on: https://code.wireshark.org/review/3761
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-08-21 07:39:58 +00:00
Guy Harris f4d24216be Add a routine to check whether all bytes implied by a 64-bit length exist.
This lets us blow up with oversized 64-bit length values, before casting
them to the 31-bit lengths we can actually handle in Wireshark, rather
than blindly casting them with weird results.

Use that in the MySQL dissector, and, if we get past the test, cast the
lengths to int to squelch warnings.

Change-Id: I3a5e9bd0027fa4ddcb9622f77952dba8f6b23c27
Reviewed-on: https://code.wireshark.org/review/3362
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-08-02 18:33:11 +00:00
Jakub Zawadzki c025152c5c Micro-optimize tvbuff:
- compute_offset_and_remaining(...) is a little bit faster than
   check_offset_length(.., .length_val =  -1);

 - tvb_find_guint8(), tvb_pbrk_guint8() - both function are limiting data to
   MIN((unsigned) maxlength, tvb_len) - do the same with less count of ifs.

Change-Id: I7761d77b6282d800eea94852d5c6543aef4bc7ca
Reviewed-on: https://code.wireshark.org/review/2829
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-07-24 05:42:28 +00:00
Guy Harris 5bfc21cf9e Clean up handling of missing functions.
With autotools, CMake, and nmake, if we have a function, #define
HAVE_{function_name_in_all_caps}, otherwise don't #define it.

If we provide our own version of a function in libwsutil, make sure we
have a header that declares it, and *ONLY* include that header if
HAVE_{function_name_in_all_caps} is *NOT* defined, so that we don't have
the system declaration and our declaration colliding.

Check for inet_aton, strncasecmp, and strptime with CMake, just as we do
with autotools.

Simplify the addition of {function_name_in_all_caps}_LO to libwsutil in
autotools.

Change-Id: Id5be5c73f79f81919a3a865324e400eca7b88889
Reviewed-on: https://code.wireshark.org/review/2903
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-07-06 21:03:09 +00:00
Jakub Zawadzki 60a6f8582a Manually revert "Make COMPUTE_OFFSET and COMPUTE_OFFSET_AND_REMAINING macros."
This reverts commit b136182ad4

This function are already marked inline, and profiler don't show much difference in performance,
revert as previous version is cleaner.

Change-Id: I1ac2c30a91b46278730ceee127efa086c7fbc6d6
Reviewed-on: https://code.wireshark.org/review/2828
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-07-03 21:09:31 +00:00
AndersBroman 8e8a4ceba3 Try to fix the builds.
Change-Id: I3ccb5c1b40504cd9314da5a09b225e3e2bf991b8
Reviewed-on: https://code.wireshark.org/review/2073
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-06-09 15:31:45 +00:00
Jakub Zawadzki fcb710baec Add sse4.2 optimized function ws_mempbrk_sse42()
In text protocols, like SIP, lot of time is spend guint8_pbrk(),
assume that text is not binary (no NULs), and use SSE4.2 pcmpistri
instruction.

Also move & rename guint8_pbrk() from tvbuff.c as _ws_mempbrk.

HAVE_SSE42 must be defined to use _ws_mempbrk_sse42() only activaded for
Windows currently.

Change-Id: Ic853d84805bdb6492c4f45d2bcc79a973fd9804e
Reviewed-on: https://code.wireshark.org/review/1730
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-06-09 12:02:27 +00:00
Evan Huus a1b939313f Revert "Don't throw for offset at end of TVB with len -1."
This reverts commit fe195c0c97.

Conflicts:
	epan/tvbuff.c

Change-Id: I1af618d0bd1e6211281b6d67c0ad197cfa513a0c
Reviewed-on: https://code.wireshark.org/review/1639
Reviewed-by: Evan Huus <eapache@gmail.com>
2014-05-14 17:12:12 +00:00
AndersBroman b136182ad4 Make COMPUTE_OFFSET and COMPUTE_OFFSET_AND_REMAINING macros.
Change-Id: I7a7b5869947499c2e0edb4de4bb462d8e8c19fc7
Reviewed-on: https://code.wireshark.org/review/1346
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-04-25 14:53:16 +00:00
Guy Harris 29eba5308f Add a get_ebcdic_string() routine, similar to other get_XXX_string() routines.
Use it in epan/tvbuff.c.

Do some other cleanups while we're at it.

Change-Id: I7aed37a568373b896aacfd23f986d445b58b77b7
Reviewed-on: https://code.wireshark.org/review/1342
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-04-25 09:30:14 +00:00
Guy Harris e1bc641c8a Fix some white space.
Change-Id: I9adec36251e27e71c530e64a472ab7562bd07fed
Reviewed-on: https://code.wireshark.org/review/1340
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-04-25 08:38:44 +00:00
Guy Harris 6a9c924460 Move the XXX-to-UTF-8 loops to routines in epan/charsets.c.
This moves a bunch of character set knowledge into epan/charsets.c.

Change-Id: Ieb79dcaac9753c77703af756b666ad2ca9385d9e
Reviewed-on: https://code.wireshark.org/review/1339
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-04-25 08:32:06 +00:00
Jakub Zawadzki 4bd8336017 Move GSM guint8 to unicode conversion functions to charsets.c
charsets.c is already place with huge number of conversion tables.
Also make gsm_default_alphabet gunichar2, all values fits in 2 bytes.

Change-Id: Ia5ab6c176b4fec21ec76b06513c1d00794ba10ef
Reviewed-on: https://code.wireshark.org/review/1328
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-04-25 04:17:58 +00:00
Jakub Zawadzki 75cb2675fd Move mktime_utc() from tvbuff.c to wsutil/time_util.c
Also do little cleanup in mktime_utc (one big #ifndef)

Change-Id: I8f721ba76cad856cfef0a2d78e7f98686f8e4e3f
Reviewed-on: https://code.wireshark.org/review/1327
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-04-25 04:13:02 +00:00
Jakub Zawadzki 993adc84d5 Fix counting/ checking for leap years in mktime_utc()
When HAVE_TIMEGM is undefined mktime_utc() might output one day shift (+86400s)
for (years <= 1967 or years >= 2100) && month >= 3

{ .tm_mday = 1 .tm_mon = 2 .tm_year = 67 }
mktime_utc() = -89436590    // Thu Mar  2 00:00:00 UTC 1967
    gmtime() = -89596800    // Wed Mar  1 00:00:00 UTC 1967

{ .tm_mday = 1 .tm_mon = 2 .tm_year = 200 }
mktime_utc() = 4107628800   // Tue Mar  2 00:00:00 UTC 2100
    gmtime() = 4107542400   // Mon Mar  1 00:00:00 UTC 2100

Change-Id: I1a544762fa5178c8798496d7dc30a2e767919149
Reviewed-on: https://code.wireshark.org/review/1287
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-04-24 06:02:48 +00:00
Evan Huus fe195c0c97 Don't throw for offset at end of TVB with len -1.
g867a1827e7dc88896ee27a107eb35c4b3973d270 introduced a change to cleanup/fix
handling of bounds checks for -1 length fields, but it ended up guaranteeing a
throw for 0-length tvbs, which isn't good; we ought to be able to add 0-length
FT_PROTOCOL items at the very least.

Better names for the function than _cheat are welcome, but I want to shut up the
buildbot.

Change-Id: I24610f947d03dac32766e2a0ffa0ff7bcc74c3e8
Reviewed-on: https://code.wireshark.org/review/1303
Reviewed-by: Evan Huus <eapache@gmail.com>
2014-04-23 15:57:13 +00:00
Guy Harris 8ab1c804d7 Another cut-and-pasteo - UCS-4/UTF-32 should fetch 4-byte characters.
Change-Id: Iff4a659cb0d0062cc149f451e49474c8db4143cd
Reviewed-on: https://code.wireshark.org/review/1292
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-04-23 04:45:17 +00:00
Jakub Zawadzki 9c8febde67 Fix copy & paste error in tvb_extract_utf_16_string, tvb_extract_ucs_4_string.
Use proper p{le,n}toh16 macro depending on endianess.

Change-Id: I8323e4296ec88e2cb24f54a1d8dc89328edb1957
Reviewed-on: https://code.wireshark.org/review/1285
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-04-23 04:33:44 +00:00
Bill Meier 0102007d0e (Trivial) Clean up a comment; Fix spelling errors; Do some whitespace changes.
Change-Id: I57fb3c0d1ba97674c01c4c4799bf36696659c82b
Reviewed-on: https://code.wireshark.org/review/1237
Reviewed-by: Bill Meier <wmeier@newsguy.com>
Tested-by: Bill Meier <wmeier@newsguy.com>
2014-04-21 16:44:25 +00:00
Hadriel Kaplan f52626cc83 Add tvb_get and proto_tree_add for string-encoded byte arrays
This commit adds tvb_get_string_bytes and proto_tree_add_bytes_item routines for
getting GByteArrays fields from the tvb when they are encoded in ASCII hex string form.

The proto_tree_add_bytes_item routine is also usable for normal
binary encoded byte arrays, and has the advantage of retrieving
the array values even if there's no proto tree.

It also exposes the routines to Lua, both so that a Lua script can take
advantage of this, but also so I can write a testsuite to test the functions.

Change-Id: I112a038653df6482a5d0ebe7c95708f207319e20
Reviewed-on: https://code.wireshark.org/review/1158
Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-04-17 14:04:19 +00:00
Hadriel Kaplan dd002649c3 Add tvb_get and proto_tree_add for string-encoded timestamps
This commit adds tvb_get_string_time and proto_tree_add_time_item routines for
getting nstime fields from the tvb when they are encoded in ASCII string form.

The proto_tree_add_time_item routine is also usable for normal
big/little-endian encoded time_t, and has the advantage of retrieving
the value even if there's no proto tree.

It also exposes the routines to Lua, both so that a Lua script can take
advantage of this, but also so I can write a testsuite to test the functions.

Change-Id: I955da10f68f2680e3da3a5be5ad8fdce7ed6808c
Reviewed-on: https://code.wireshark.org/review/1084
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-04-14 11:47:39 +00:00
Pascal Quantin cfe11b1097 Add ENC_ASCII_7BITS encoding
Change-Id: I01ec87ff4181afb5b2de487fd5f5200f8d62f17d
Reviewed-on: https://code.wireshark.org/review/1088
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
2014-04-13 20:02:52 +00:00
Guy Harris cb16dff992 Get rid of more tvb_get_nstringz* calls.
Add an FT_STRINGZPAD type, for null-padded strings (typically
fixed-length fields, where the string can be up to the length of the
field, and is null-padded if it's shorter than that), and use it.  Use
IS_FT_STRING() in more cases, so that less code needs to know what types
are string types.

Add a tvb_get_stringzpad() routine, which gets null-padded strings.
Currently, it does the same thing that tvb_get_string_enc() does, but
that might change if we don't store string values as null-terminated
strings.

Change-Id: I46f56e130de8f419a19b56ded914e24cc7518a66
Reviewed-on: https://code.wireshark.org/review/1082
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-04-12 22:27:22 +00:00
Guy Harris ae127f23fa Add Mac Roman and DOS CP437.
Change-Id: Ib96f2cf4ea71cd0cc2c703d58b9d254bf4c1248a
Reviewed-on: https://code.wireshark.org/review/1077
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-04-12 08:54:06 +00:00
AndersBroman df80f3133c Fix a typo
Change-Id: Ie32a140e49140a92c69cb6fa84cdc55402516830
Reviewed-on: https://code.wireshark.org/review/935
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-04-03 04:39:06 +00:00
AndersBroman 67cc462941 Don't use external function internaly to avoid multiple checks.
tvb_captured_length()                      -> tvb->length
tvb_captured_length_remaining(tvb, offset) -> (Inline) _tvb_captured_length_remaining()
tvb_get_ptr()                              -> ensure_contiguous()

Change-Id: I3540854c9b51ca9c3319b030c7d91b4aff976a26
Reviewed-on: https://code.wireshark.org/review/922
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-04-03 04:08:45 +00:00
AndersBroman 84bc050a89 In the string handling routines don't call tvb_get_...() inside the loops insted get the ptr and read
directly avoiding the overhead of calling fast_ensure_contiguous()
repeatibly.

Change-Id: Ib5eee87ef9d49cb4e46b3b9c3d3db0134d3c4a32
Reviewed-on: https://code.wireshark.org/review/889
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-04-03 04:08:00 +00:00
AndersBroman 01b65269bf Inlining some tvb function gives a 6% performance gain according to
valgrind.

Change-Id: I7881f8c1407d422a3f1ad5bc17e975b45703db74
Reviewed-on: https://code.wireshark.org/review/909
Reviewed-by: Evan Huus <eapache@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-04-01 15:41:33 +00:00
Guy Harris d156deff04 Rename "size" variable to "length", to match other string routines.
Change-Id: I385345cfafc7e7b4d3e66713fb0fe570b39f438d
Reviewed-on: https://code.wireshark.org/review/865
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-03-29 20:23:09 +00:00
Evan Huus 521bab1e1c Use sized strbufs when extracting tvb strings
We rarely know exactly how long a string will be, but we frequently have a good
lower bound (that's better than the default strbuf size of 16). Starting at that
size probably reduces the amount of allocation/copying needed.

Also make use of the new _finalize() method to save memory and avoid constness
problems.

Change-Id: I3f043bd12c1ccfce5990168fb6531ecd287bec5b
Reviewed-on: https://code.wireshark.org/review/856
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Evan Huus <eapache@gmail.com>
2014-03-29 20:01:17 +00:00
Bill Meier 99b55eb7a6 Fix a typo in a comment; use consistent indentation matching that specified by the editor modelines.
Change-Id: I6d4ad3675ec9099913c8a32ad1f2758316158f68
Reviewed-on: https://code.wireshark.org/review/587
Reviewed-by: Bill Meier <wmeier@newsguy.com>
Tested-by: Bill Meier <wmeier@newsguy.com>
2014-03-10 13:27:03 +00:00
Alexis La Goutte 296591399f Remove all $Id$ from top of file
(Using sed : sed -i '/^ \* \$Id\$/,+1 d')

Fix manually some typo (in export_object_dicom.c and crc16-plain.c)

Change-Id: I4c1ae68d1c4afeace8cb195b53c715cf9e1227a8
Reviewed-on: https://code.wireshark.org/review/497
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-03-04 14:27:33 +00:00
Guy Harris 8d234a0d8c More tvbuff API deprecation, comment expansion, and documentation updates.
Do with tvb_get_stringz() what was done with tvb_get_string().

Redo the comments for the string get routines to try to give more detail
in a fashion that's a bit less hard to read.

Warn, in comments, of the problems with using
tvb_get_string()/tvb_get_stringz() (i.e., if your strings are non-ASCII,
all bytes with the 8th bit set are going be replaced by the Unicode
REPLACEMENT CHARACTER, and displayed as such).

Warn, in a comment, of the problems with tvb_get_const_stringz() (i.e.,
it gives you raw bytes, rather than guaranteed-to-be-valid UTF-8).

Update documentation and release notes appropriately.

Change-Id: Ibd3efb92a203861f507ce71bc8d04d19d9d38a93
Reviewed-on: https://code.wireshark.org/review/327
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-02-26 22:04:08 +00:00
Bill Meier 11b5c15fdb Remove trailing whitespace
Change-Id: I8116f63ff88687c8db3fd6e8e23b22ab2f759af0
Reviewed-on: https://code.wireshark.org/review/385
Reviewed-by: Bill Meier <wmeier@newsguy.com>
Tested-by: Bill Meier <wmeier@newsguy.com>
2014-02-25 20:46:49 +00:00
Evan Huus 22149c5523 TVB API deprecations and cleanup
- rename tvb_length and similar to tvb_captured_length and similar; leave
  #defines in place for backwards-compat, but mark them clearly as deprecated in
  code comments and in checkAPI
- remove tvb_get_string as C code and just leave a #define in place for
  backwards-compat; mark it clearly as deprecated in code comment and checkAPI
- update READMEs and sample dissector for all of the above
- while in the neighbourhood, make checkAPI skip (and warn) for missing files
  instead of bailing on the whole check, so subsequent files still get checked

Change-Id: I32fc437896ca86ca73e9b49d5f50400adf8ec5ad
Reviewed-on: https://code.wireshark.org/review/311
Reviewed-by: Evan Huus <eapache@gmail.com>
2014-02-22 15:02:01 +00:00
Guy Harris 4d9475e4ef Get rid of tvb_get_faked_unicode() - tvb_get_string_enc() does the job
better.

We don't need eventlog_get_unicode_string_length() in the eventlog
dissector, either - tvb_unicode_strsize() does the job just as well.

svn path=/trunk/; revision=54874
2014-01-21 09:56:34 +00:00
Guy Harris 9cdf8dd5f5 Don't do the byte-with-8th-bit-set-to-REPLACEMENT-CHARACTER mapping for
UTF-8 strings.

Add that mapping for null-terminated ASCII strings.

Factor out some common parts of comments about string routines, and
clean up some other comments.

svn path=/trunk/; revision=54868
2014-01-21 01:23:29 +00:00
Martin Kaiser 26701ed0f7 remove todo comments
svn path=/trunk/; revision=54865
2014-01-20 21:56:38 +00:00
Martin Kaiser 933e95c8ec tvb_get_string(): replace 8bit characters with the unicode replacement char
svn path=/trunk/; revision=54864
2014-01-20 21:39:00 +00:00
Guy Harris 9228c72ef0 Explain casting away const.
svn path=/trunk/; revision=54816
2014-01-15 08:35:55 +00:00
Jakub Zawadzki d1dcee936b Move defines for helping with UTF-16 surrogate pairs to wsutil/unicode-utils.h
tvbuff version was moved, but with 'or' optimization from packet-json.

svn path=/trunk/; revision=54632
2014-01-07 21:55:49 +00:00
Bill Meier b26f50cbb1 (Trivial) explicitely --> explicitly
svn path=/trunk/; revision=54594
2014-01-04 17:29:20 +00:00
Pascal Quantin 6ebc058f47 Add proto_tree_add_ts_23_038_7bits_item() / tvb_get_ts_23_038_7bits_string() functions and update dissectors to use it.
Remove gsm_sms_char_7bit_unpack() / gsm_sms_chars_to_utf8() functions.
Update documentation a bit.

svn path=/trunk/; revision=54534
2014-01-01 14:33:19 +00:00
Jakub Zawadzki a65cbe8e7b Add new function: tvb_skip_guint8()
svn path=/trunk/; revision=54505
2013-12-30 23:58:45 +00:00
Guy Harris a8ac118885 Use Unicode REPLACEMENT CHARACTER for TS 23.038 errors, as we do for
unassigned code points in some other character sets.

svn path=/trunk/; revision=54477
2013-12-27 23:55:23 +00:00
Guy Harris 5f91a0afc7 Oops, escape characters shouldn't cause anything to be added to the
string, they should just cause TRUE to be returned - it's the *next*
code point that gets treated specially and, after mapping, added to the
string.

svn path=/trunk/; revision=54431
2013-12-24 01:03:59 +00:00
Evan Huus 5a81522aa2 Make sure uchar is always initialized. Just use '?' since the comment indicates
that it's a weird (undefined?) case.

svn path=/trunk/; revision=54430
2013-12-24 00:54:30 +00:00
Guy Harris bd8aeb9054 Update some comments.
svn path=/trunk/; revision=54429
2013-12-24 00:23:09 +00:00
Guy Harris 0d7a48a8bf Add a ENC_3GPP_TS_23_038 encoding, for the standard SMS alphabet in a
bit-packed string, and use it in some places.

svn path=/trunk/; revision=54428
2013-12-24 00:20:09 +00:00
Guy Harris eb3ff1396f Fix warning.
svn path=/trunk/; revision=54375
2013-12-23 02:19:27 +00:00
Guy Harris 8a5d226894 Fix the offset constant in SURROGATE_VALUE(), and add rather than OR it.
Expand a bunch of comments, discussing what various routines do and
should perhaps do.

Pull the core of tvb_get_ucs_2_string()/tvb_get_ucs_2_stringz() and
tvb_get_ucs_4_string()/tvb_get_ucs_4_stringz() into common routines, as
we did for tvb_get_utf_16_string()/tvb_get_utf_16_stringz().

svn path=/trunk/; revision=54374
2013-12-23 01:25:20 +00:00
Bill Meier e348c13deb (Trivial)
- Minor whitespace changes;
- Fix a typo;
- Add editor modelines to tnbuff_subset.c

svn path=/trunk/; revision=54364
2013-12-22 15:47:17 +00:00
Bill Meier 400a1fcd60 Use G_GINT64_CONSTANT(n) rather than 'nLL' when defining constants;
Fix a typo in a comment.

svn path=/trunk/; revision=54357
2013-12-22 14:43:35 +00:00
Jakub Zawadzki 1f88687d3f tvb_get_ucs_4_string: increase offset by 4
copy&paste of tvb_get_ucs_2_string?

svn path=/trunk/; revision=54353
2013-12-22 10:45:22 +00:00
Guy Harris fc7a77189d Add UCS-4 support, and use it.
Shuffle the character ENC_ values around a bit, keeping the Unicode
encodings together, moving the Windows code pages (only one for now)
after the ISO 8859 encodings, and putting "I can't believe it's not
ASCII!" at the end.

Fix some comment typoes, and update another comment, while we're at it.

svn path=/trunk/; revision=54351
2013-12-22 08:45:57 +00:00
Guy Harris f231a273f2 Add the rest of ISO-8859-n, thanks to Jakub's "generate a mapping table"
program.

Put the character-encoding cases in order.

svn path=/trunk/; revision=54344
2013-12-21 21:55:46 +00:00
Guy Harris 92f177ec97 Get rid of tvb_get_unicode_string() and tvb_get_unicode_stringz();
instead, have static routines to get UCS-2 (no surrogate pairs) and
UTF-16 (with surrogate pairs) strings, with the routines to handle
UTF-16 actually handling surrogate pairs.

Update some out-of-date comments while we're at it.

svn path=/trunk/; revision=54318
2013-12-21 01:42:41 +00:00
Evan Huus a6415ece0a Rename a couple of to_str functions to have ep_ in the name. This makes it
obvious that the returned string is ephemeral, and opens up the original names
in the API for versions that take a wmem pool (and thus can work in any scope).

svn path=/trunk/; revision=54249
2013-12-19 15:49:09 +00:00
Jakub Zawadzki 099294dd16 Add charset table for ISO/IEC 8859-9 (ENC_ISO_8859_9)
svn path=/trunk/; revision=54239
2013-12-18 23:32:06 +00:00
Evan Huus 8f665d9b36 Add a sixteenth element to all BCD digit sets to avoid garbage values when
decoding corrupt bytes. Some of these digit sets could probably be
deduplicated...

svn path=/trunk/; revision=54224
2013-12-18 15:54:32 +00:00
Jakub Zawadzki 0de43ce2dd Create sign extension routines in <wsutil/sign_ext.h>, use it in few places.
svn path=/trunk/; revision=54197
2013-12-17 21:36:33 +00:00
Michael Mann 79d336c664 Handle signed integers > 32 bits. Bug 8454 (https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8454)
svn path=/trunk/; revision=54183
2013-12-17 16:50:33 +00:00
Martin Kaiser a07c0ff146 add support for ISO 8859-5
svn path=/trunk/; revision=54132
2013-12-15 19:13:31 +00:00