Commit Graph

61 Commits

Author SHA1 Message Date
Evan Huus f4aa108913 tvbparse: explicitly memory-scope parser
Avoids the use of the global memory pool in favour of one the compiler
actually knows must be in scope.

Also delete a few-hundred lines of if-0ed code that hadn't been active
in 15+ years.
2021-09-16 06:54:42 +00:00
João Valverde 133b0c583f Move epan/wmem/wmem_scopes.h to epan/
This header was installed incorrectly to epan/wmem_scopes.h.

Instead of creating additional installation rules for a single
header in a subfolder (kept for backward compatibility) just
rename the standard "epan/wmem/wmem.h" include to
"epan/wmem_scopes.h" and fix the documentation.

Now the header is installed *correctly* to epan/wmem_scopes.h.
2021-07-26 14:56:11 +00:00
João Valverde 0e50979b3f Replace g_assert() with ws_assert() 2021-06-19 01:23:31 +00:00
João Valverde 39df3ae3c0 Replace g_log() calls with ws_log() 2021-06-16 12:50:27 +00:00
Moshe Kaplan 180b5e5dc0 Replace more g_malloc with g_new
Replace g_malloc with g_new to improve
source code readability.
2020-12-23 11:47:17 +00:00
Moshe Kaplan e16166a74c Detect and replace bad allocation patterns
Adds a pre-commit hook for detecting and replacing
occurrences of `g_malloc()` and `wmem_alloc()` with
`g_new()` and `wmem_new()`, to improve the
readability of Wireshark's code, and
occurrences of
`g_malloc(sizeof(struct myobj) * foo)`
with
`g_new(struct myobj, foo)`
to prevent integer overflows

Also fixes all existing occurrences across
the codebase.
2020-12-22 14:56:38 +00:00
Moshe Kaplan 3b47a55b0d Replace instances of wmem_alloc with wmem_new
This commit replaces instances of
  (myobj *)wmem_alloc(wmem_X_scope(), sizeof(myobj))
and replaces them with:
  wmem_new(wmem_X_scope(), myobj)
to improve the readability of Wireshark's code.

Replacements were made with the following Python script:

import os
import re
import sys

pattern = r'\(([^\s\n]+) ?\*\) ?wmem_alloc(0?)\((wmem_[a-z]+_scope\(\)), sizeof\(\1\)\)'
replacewith = r'wmem_new\2(\3, \1)'

startdir = sys.argv[1]

for root, dirs, files in os.walk(startdir):
    for fname in files:
        fpath = os.path.join(root, fname)
        if not fpath.endswith('.c'):
            continue
        with open(fpath, 'r') as fh:
            fdata = fh.read()
        output = re.sub(pattern, replacewith, fdata)
        if fdata != output:
            print(fpath)
            with open(fpath, 'w') as fh:
                fh.write(output)

Change-Id: I223cb2fcce336bc99ca21c4a74e4cf758fd00572
Reviewed-on: https://code.wireshark.org/review/38088
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-08-08 09:54:29 +00:00
Guy Harris 20800366dd HTTPS (almost) everywhere.
Change all wireshark.org URLs to use https.

Fix some broken links while we're at it.

Change-Id: I161bf8eeca43b8027605acea666032da86f5ea1c
Reviewed-on: https://code.wireshark.org/review/34089
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-07-26 18:44:40 +00:00
Dario Lombardo b67b47558d epan: remove redundant casts.
Found by clang-tidy.

Change-Id: Iaf6cf84c33b03ddfcd39a333b49f4987002afa56
Reviewed-on: https://code.wireshark.org/review/31338
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-01-03 23:39:43 +00:00
Gerald Combs 8f08a4e74e Try to discourage the use of APIs via counting.
Add the ability to specify maximum function counts for each group to
checkAPIs. Add maximum counts for the "termoutput" and "abort" groups
where needed. Show summaries in various checkAPI targets.

Switch uses of ws_g_warning back to plain g_warning.

Change-Id: I5cbddc8c671729e424eed8551f69116d16491976
Reviewed-on: https://code.wireshark.org/review/29721
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-09-19 16:07:03 +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
Stig Bjørlykke c51560985a Fix tvbparse recursion limit check.
When doing recursion check we must also count down when done.

Bug: 14253
Change-Id: Icacc86e8b25e106e151117dbcc2f132b1bbe898e
Reviewed-on: https://code.wireshark.org/review/25226
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-01-09 16:21:36 +00:00
Gerald Combs 94479aded1 Limit tvbparse recursion.
Add a recursion check to tvbparse so that we don't overflow our stack.

Bug: 14253
Change-Id: I0f667c3720311318267a1184b33e33253f8ff729
Reviewed-on: https://code.wireshark.org/review/25202
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2018-01-08 23:55:13 +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
Peter Wu 0bae8424fe tvbparse: fix memleak
Use same wmem_epan_scope() as "w" (tvbparse_wanted_t).

Change-Id: I73fdb1fb3b55a91b7bb0fc36e435024c6f0b3d73
Ping-Bug: 12790
Reviewed-on: https://code.wireshark.org/review/17361
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2016-08-28 22:07:22 +00:00
Michael Mann 907d49483d Fix some of the checkAPIs.pl warnings for g_warning.
1. Create ws_g_warning for legitimate uses of g_warning
2. Use proto_tree_add_debug_text
3. Comment some out

Change-Id: Ida044bf40286b955fdd529c4f9907c8e09b3d7c5
Reviewed-on: https://code.wireshark.org/review/16678
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>
2016-07-26 04:08:50 +00:00
Dario Lombardo 0d4569851c tvbparse: change g_hash_table to wmem_map.
Change-Id: I245595051617f6d6333314240825a526adf19339
Reviewed-on: https://code.wireshark.org/review/15244
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-06-14 19:34:12 +00:00
Dario Lombardo 374d1207a5 tvbparse: change g_malloc to wmem_alloc.
Change-Id: I6a6363400d9fd1d76b9de0c5deea83dfc7cea1e2
Reviewed-on: https://code.wireshark.org/review/15245
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-06-14 19:32:31 +00:00
Dario Lombardo 30d1afb6be tvbparse: change g_strdup_printf to wmem_strdup_printf.
Change-Id: I57ff604d23967eb1f6481c7019e3eab0389dc3a5
Reviewed-on: https://code.wireshark.org/review/15257
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2016-06-13 19:38:12 +00:00
João Valverde 8e1ade8516 Use cast to char for explicit conversion [-Woverflow]
Change-Id: If33cf41f46f2be9c66fc4a626af6a2c010fba7d3
Reviewed-on: https://code.wireshark.org/review/13931
Reviewed-by: Michael Mann <mmann78@netscape.net>
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>
2016-02-15 18:36:14 +00:00
Michael Mann 3606f80d9e Officially remove tvb_get_string and tvb_get_stringz.
Almost all replacements were done awhile ago, just put the final nail in the coffin.

Change-Id: I0a708d886da5a500c2a1e2c9ee2736794bdb9411
Reviewed-on: https://code.wireshark.org/review/12206
Reviewed-by: Michael Mann <mmann78@netscape.net>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-11-27 05:11:25 +00:00
Michael Mann 51360b5380 Eliminate proto_tree_add_text from odds and ends.
A few calls in the epan directory and comments in the ui directory

Change-Id: Ia8f8830ac6909ab94d3a03283bfd173456bc9718
Reviewed-on: https://code.wireshark.org/review/10492
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-09-15 02:20:13 +00:00
Daniel Mack b125feae21 epan: fix build error with gcc5
gcc5 bails out with the below error.

  CC       libwireshark_la-tvbparse.lo
  CC       libwireshark_la-tvbuff_base64.lo
tvbparse.c: In function 'cond_not_char':
tvbparse.c:254:18: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
     if (! offset < tt->end_offset ) {
                  ^
cc1: all warnings being treated as errors
Makefile:1843: recipe for target 'libwireshark_la-tvbparse.lo' failed

Change-Id: I4e8654e97079da6b39be580fc766eecefb4c7ea6
Reviewed-on: https://code.wireshark.org/review/7339
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-02-24 09:10:46 +00:00
Michael Mann b5eb9710db Replace all remaining instances of ep_new with wmem_new and wmem_packet_scope.
Change-Id: I50b2cd0e233554bc58082e96e8d879b40edfc0c1
Reviewed-on: https://code.wireshark.org/review/6595
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-01-17 23:22:46 +00:00
Bill Meier 23e78cd6bd Add editor modelines; Adjust whitespace as needed.
Change-Id: I3dc57f4c2ca57585103e3b71503ac4c332903e50
Reviewed-on: https://code.wireshark.org/review/4594
Reviewed-by: Bill Meier <wmeier@newsguy.com>
2014-10-10 14:50:08 +00:00
Pascal Quantin 3e5ef80b29 tvbparse: do not increment the token length when the new sub token length is 0
It fixes the unwanted addition of ignore characters when using tvbparse_some as seen with the capture from bug 10417

Change-Id: If68b587e1821fb34aa1fb56666986e1fa6385c33
Reviewed-on: https://code.wireshark.org/review/3905
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
2014-09-03 20:32:07 +00:00
Yan Burman 4aad9d3b58 Fix compilation warning
Change-Id: Ia7922415d8b22ba0c5a04ad6940c7e10bc205d57
Reviewed-on: https://code.wireshark.org/review/2371
Reviewed-by: Evan Huus <eapache@gmail.com>
2014-06-18 07:23:38 +00:00
Jakub Zawadzki 57b27ec250 Optimize tvbparse character set checking.
This patch makes tvbparse_[not_]chars() to generate
array of characters which is accepted,
later this array is checked in cond_chars_common().

This results in nice speedup of XML dissector (~33% for my file).

Change-Id: I62a5585f8bccaaea1a0c49fc70c7552531493442
Reviewed-on: https://code.wireshark.org/review/2356
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-06-18 05:52:36 +00:00
AndersBroman 3eacdda619 Change ep_alloc() to wmem_new() change depcrecated API.
Change-Id: I1eb3d3f3ccdfa265099446e8d609273867304a73
Reviewed-on: https://code.wireshark.org/review/1936
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-06-03 14:34:57 +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 d363ef35ca tvparse_until() is used, so don't make it static.
svn path=/trunk/; revision=54738
2014-01-13 23:03:30 +00:00
Guy Harris c9778167ea #if 0 out unused routines claimed to be "untested" and #if 0'ed out in
epan/tvparse.h, and static routines used by that code.

svn path=/trunk/; revision=54727
2014-01-13 22:20:25 +00:00
Evan Huus 7151a4d99e Replace all(?) remaining ep_stack occurences with wmem stacks.
svn path=/trunk/; revision=54435
2013-12-24 03:29:14 +00:00
Pascal Quantin a0c53ffaa1 emem -> wmem conversion:
- ep_tvb_get_bits() -> wmem_packet_tvb_get_bits()
- tvb_g_memdup()/ep_tvb_memdup() -> tvb_memdup()
- tvb_fake_unicode()/tvb_get_ephemeral_faked_unicode() -> tvb_get_faked_unicode()
- tvb_get_g_string()/tvb_get_ephemeral_string()/tvb_get_seasonal_string() -> tvb_get_string()
- tvb_get_g_unicode_string()/tvb_get_ephemeral_unicode_string() -> tvb_get_unicode_string()
- tvb_get_ephemeral_string_enc() -> tvb_get_string_enc()
- update docs accordingly

svn path=/trunk/; revision=52172
2013-09-22 15:50:55 +00:00
Pascal Quantin 95938370bd From Ed Beroset via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8416 :
Remove C++ incompatibilities from tvbparse and tvbuff

svn path=/trunk/; revision=48025
2013-03-02 23:05:27 +00:00
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 b18e880040 Update FSF address - part II.
svn path=/trunk/; revision=43538
2012-06-28 23:18:38 +00:00
Chris Maynard 2551c6122e Wrap a couple of very long lines.
svn path=/trunk/; revision=41770
2012-03-26 17:33:09 +00:00
Chris Maynard 2cd8459ddb From Jakub Zawadzki via bug 4753: New dissector: JSON, w/minor changes by me:
1) Add links to RFC 4627 and the json.org web site.
2) Comment out hf_json_member_key to keep tools/checkhf.pl happy.
3) Avoid duplicate (application/json) from being displayed in Info column.

svn path=/trunk/; revision=35317
2010-12-31 18:03:23 +00:00
Bill Meier 0d372283b3 (Trivial): indentation & whitespace cleanup.
svn path=/trunk/; revision=32366
2010-04-03 19:20:07 +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
Bill Meier 9d663d7081 Fix various gcc -Wshadow warnings.
svn path=/trunk/; revision=31720
2010-01-28 18:45:46 +00:00
Gerald Combs c2ae798ae2 More size_t fixes.
svn path=/trunk/; revision=28000
2009-04-08 17:31:12 +00:00
Bill Meier ea2d615dd7 Fix some typos and spelling (mostly in text strings)
svn path=/trunk/; revision=27068
2008-12-20 01:01:28 +00:00
Luis Ontanon 42c3239a1a luis.ontanon@gmail.com => luis@ontanon.org
svn path=/trunk/; revision=25937
2008-08-05 21:03:46 +00:00
Stephen Fisher 8fd3ee0560 Remove almost all of the casts I committed recently and in place of
them, add -Wno-pointer-sign to CFLAGS when gcc will accept it.


svn path=/trunk/; revision=21253
2007-03-28 21:55:11 +00:00
Stephen Fisher 46b8669566 Fix a bunch more warnings. Add -Werror when using --with-warnings-as-errors
under gcc to tools/lemon, plugins/mate and epan/


svn path=/trunk/; revision=21204
2007-03-26 06:10:52 +00:00
Ronnie Sahlberg 89f022b12b name change
svn path=/trunk/; revision=18197
2006-05-21 05:12:17 +00:00