Commit Graph

176 Commits

Author SHA1 Message Date
Guy Harris 76b08ea083 Fix spelling errors.
The Ubuntu build commented on some spelling errors in executable code
files.  Fix the errors that don't come from external files containing
the spelling errors (USB product and vendor IDs, PCI IDs, ASN.1
specifications), and fix some errors that don't show up in the
executable code files (e.g., in comments and variable names).
2021-09-11 10:01:27 +00:00
Guy Harris 3cb6403a4c wiretap: always allocate a block for a record.
Without that, you could add a comment to a record in a file format the
reading code for which doesn't allocate blocks, but the comment doesn't
get saved, as there's no block in which to save the comment option.

This simplifies some code paths, as we're either using the record's
modified block or we're using the block as read from the file, there's
no third possibility.

If we attempt to read a record, and we get an error, and a block was
allocated for the record, unreference it, so the individual file readers
don't have to worry about it.
2021-08-29 19:12:13 -07:00
Alexis La Goutte a3f9c6bc45 erf: Fix Dead Store (found by Clang Anlyzer)
Although the value stored to 'tagtotallength' is used in the enclosing expression, the value is never actually read from 'tagtotallength'
2021-07-30 20:43:55 +00:00
Guy Harris c64a9bbde7 erf: make a copy of the first SHB comment.
We free it, but what wtap_block_get_nth_string_option_value() returns is
what's stored in the block, and it might get freed up out from under us.
Save a copy of it, so that when we free it, we're not double-freeing.
2021-07-16 15:59:58 -07:00
Guy Harris 7b0c4950a5 wiretap: clean up option definitions a bit.
Spell out "DESCRIPTION" for the IDB description option, as it's spelled
out in the pcapng spec.

Put the #defines for various options in the same order as the block
types for them are in the pcapng spec.
2021-07-14 06:55:12 +00:00
Guy Harris dd5907d2a3 Consistently refer to blocks that have been modified as "modified".
"User" sounds as if the blocks belong to the user; at most, the current
user might have modified them directly, but they might also have, for
example, run a Lua script that, unknown to them, modified comments.
Also, a file might have "user comments" added by a previous user, who
them wrote the file and and provided it to the current user.

"Modified" seems a bit clearer than "changed".
2021-07-08 00:05:35 -07:00
David Perry 73087d6fb4 Use wtap_blocks for packet comments
Mostly functioning proof of concept for #14329. This work is intended to
allow Wireshark to support multiple packet comments per packet.

Uses and expands upon the `wtap_block` API in `wiretap/wtap_opttypes.h`.
It attaches a `wtap_block` structure to `wtap_rec` in place of its
current `opt_comment` and `packet_verdict` members to hold OPT_COMMENT
and OPT_PKT_VERDICT option values.
2021-07-07 18:40:24 +00:00
Guy Harris c1082bd99e wiretap: have the "for each option" routine return a success/fail indication.
Have the routine it calls return a Boolean value, with "true" meaning
"keep going" and "false" meaning "stop iterating and return a failure
indication".  If the callback routine never returns "false", the routine
returns "true" as a success indication.
2021-06-27 13:25:16 -07:00
Guy Harris 1fe3ed4940 erf: fix a comment to match reality.
It's not that Wireshark only supports one copy of some block options,
it's that *the pcapng specification* only supports one instance of some
block options, and it's not that wtap_block_set_*_value() fails on
non-string values, it's that the set_XXX_option_value routines currently
only support changing the value of an existing option, not adding a new
instance of an option - the latter requires the add_XXX_option_value
routine.
2021-06-19 15:37:43 -07:00
Guy Harris 02cffb51a9 erf: handle errors in some routines more completely.
Have them take error code and error information string arguments and,
for various failures, fill them in as "internal error" indications.

Check their return codes to see if they got an error.
2021-06-18 16:22:54 -07:00
Guy Harris 49ec11f5aa erf: set the tsprecision value of a newly-created IDB.
Don't assume the default is correct, because there's no guarantee of
that - in fact, there's currently a guarantee that it's not, as it's
initialized to 0, which is WTAP_TSPREC_SECS.
2021-06-18 01:24:41 -07:00
Guy Harris 48ba793ef6 erf: clean up handling the return value when getting and option value.
Make the variable into which we put the return value of
wtap_block_get_nth_string_option_value() a wtap_opttype_return_val, as
that's the type of the return value - it's not a boolean, it's a status
code with multiple values.

Explicitly check that value against WTAP_OPTTYPE_SUCCESS.  Yes,
WTAP_OPTTYPE_SUCCESS is 0, so

	if (xxx)

is equivalent to

	if (xxx != WTAP_OPTTYPE_SUCCESS)

but it's better to make it explict, so it's clear that it's checking for
failure.
2021-05-24 23:39:26 -07:00
Guy Harris 297b6c5407 erf: set USERAPPL if we have the application version but not the name.
Just say "(Unknown application) <version>".

This also means that we don't leak the app_version string if there's no
app_name string.
2021-05-23 19:37:09 -07:00
Gerald Combs e513ed41d2 Wiretap: Fix some compiler warnings.
Make various _dump_can_write_encap and _dump_open routines static. Add a
couple of casts.
2021-04-16 20:09:42 +00:00
Dario Lombardo ea929d6401 wsutils: add local implementation of g_memdup2.
g_memdup() was deprecated and replaced with g_memdup2() in GLib 2.68,
we provide our own copy of g_memdup2() for older GLib versions.
2021-03-25 09:38:10 +00:00
Guy Harris 8f965899b3 Remove unnecessary includes of wiretap/pcap-encap.h. 2021-03-15 16:04:02 -07:00
Guy Harris ce20c00049 Remove unnecessary inclues of wiretap/pcapng.h. 2021-03-15 15:29:40 -07:00
Guy Harris ed86f51e49 wiretap: rename wtap_register_file_type_subtypes().
It only registers one file type/subtype, so rename it to
wtap_register_file_type_subtype().

That will also force plugins to be recompiled; that will produce compile
errors for some plugins that didn't change to match the new contents of
the file_type_subtype_info structure.

Also check to make sure that the registered file type/subtype supports
at least one type of block; a file type/subtype that doesn't return
*any* blocks and doesn't permit *any* block types to be written is not
very useful.  That should also catch most if not all other plugins that
didn't change to match the new contents of the file_type_subtype_info
structure.

Don't make errors registering a file type/subtype fatal; just complain,
don't register the bogus file type/subtype, and drive on.
2021-02-23 20:39:16 -08:00
Guy Harris 842a7cccf9 wiretap: have file handlers advertise blocks and options supported.
Instead of a "supports name resolution" Boolean and bitflags for types of
comments supported, provide a list of block types that the file
type/subtype supports, with each block type having a list of options
supported.  Indicate whether "supported" means "one instance" or
"multiple instances".

"Supports" doesn't just mean "can be written", it also means "could be
read".

Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to
indicate that it provides, in addition to information about the
interface, an ID (implicitly, in pcapng files, by its ordinal number)
that is associated with every packet in the file.  Emphasize that in
comments - just because your capture file format can list the interfaces
on which a capture was done, that doesn't mean it supports this; it
doesn't do so if the file doesn't indicate, for every packet, on which
of those interfaces it was captured (I'm looking at *you*, Microsoft
Network Monitor...).

Use APIs to query that information to do what the "does this file
type/subtype support name resolution information", "does this file
type/subtype support all of these comment types", and "does this file
type/subtype support - and require - interface IDs" APIs did.

Provide backwards compatibility for Lua.

This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's
iptrace; do so.
2021-02-21 23:18:35 +00:00
Guy Harris c80c16759b wiretap: eliminate two WTAP_FILE_TYPE_SUBTYPE_ values.
Eliminate WTAP_FILE_TYPE_SUBTYPE_ERF and
WTAP_FILE_TYPE_SUBTYPE_SYSTEMD_JOURNAL - instead, fetch the values by
name, using wtap_name_to_file_type_subtype().

This requires that wtap_init() be called before epan_init(); that's
currently the case, but put in comments to indicate why it must continue
to be the case.
2021-02-19 23:20:24 +00:00
Guy Harris 09684644ee wiretap: clean up WTAP_BLOCK_ names.
Remove NG from the names - it adds nothing.

Don't use the abbreviations for pcapng block names, spell out what the
block does (e.g. "WTAP_BLOCK_DECRYPTION_SECRETS" rather than
"WTAP_BLOCK_DSB"), to make it more obvious what the block does.

Spell out some other abbreviations.

Add WTAP_BLOCK_PACKET for future use for packet blocks; there's no need
to distinguish between the Enhanced Packet Block, the Simple Packet
Block, and the deprecated Packet Block here.
2021-02-09 22:32:57 +00:00
Guy Harris 0773147a55 wiretap: redo the way we handle if_filter IDB options.
Change the data structure for that option to have a type field,
indicating that it's either a pcap filter string or a BPF program,
followed by a union with a string-pointer member for pcap filter strings
and an instruction-count-and-pointer-to-instructions structure for BPF
programs.

Have routines to add, set, and fetch that option that handle that
structure; discard the "generic structured option" routines.  That means
there's more type checking possible at compile time.

Add more code to handle BPF programs.

When writing pcapng files, check, both for that option and for string
options, whether the option length is too big for the data to fit in a
pcapng option, and don't write it if it is.  (XXX - truncate the data?
Report an error?)
2021-02-01 16:50:01 -08:00
Guy Harris ca85c516fe Refer to options whose data isn't a simple data type as "structured".
"Custom", as in "requires custom handling of the option data, collides
with "custom", as in pcapng custom options.
2021-01-30 00:12:11 -08: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 c4d19650d5 wiretap/erf: Use memmove instead of memcpy
It's possible for memcpy's source and destination
to be the same address, and so therefore
'overlap'. Use memmove instead, which
is safe for overlapping regions.
This fixes Coverity 1450802.
2020-12-09 00:24:58 +00:00
Guy Harris 6e6233521a Have WTAP_ERR_INTERNAL include an err_info string giving details.
That way, users won't just see "You got an internal error", the details
will be given, so they can report them in a bug.
2020-10-14 04:51:45 +00:00
Роман Донченко 69e1aa860b Fix many spelling errors 2020-10-11 08:35:55 +00:00
Guy Harris a883081b70 Update URLs pointing to the bug database.
Switch from bugs.wireshark.org to the GitLab issues list.
2020-10-03 07:54:12 -07:00
Minh Phan 88aec0ecd9 editcap: fix time adjustment for ERF
The erf_dump function in erf.c keeps the header intact and
ignores the adjusted time.
This adds a section for checking if the timestamp is changed
and updating the header accordingly.

Bug: 16578
Change-Id: I14468a302e746c7a84cf5619b73b94850142d930
Reviewed-on: https://code.wireshark.org/review/37301
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-06-01 06:51:55 +00:00
Guy Harris 7d95c27de2 ERF: split wiretap/erf.h into three files.
wiretap/erf_record.h has declarations for records in ERF files and in
LINKTYPE_ERF packets in pcap and pcapng files.

wiretap/erf-common.h has declarations of routines to be called by
pcap/pcapng reader code when processing LINKTYPE_ERF packets.

wiretap/erf.h is what's left, for use by wiretap/erf.c and the code with
the tables of file readers and writers.

Change-Id: Ia982e79b14a025a80dcbc7c812fb3b2cdb9c6aaa
Reviewed-on: https://code.wireshark.org/review/37021
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-05-02 04:24:08 +00:00
Guy Harris 9d30864607 wiretap/erf: Get rid of no-longer-used routine.
I guess the "replace" part of "TODO: Replace uses in pcapng and pcap
with erf_read_header() and/or erf_populate_interface_from_header() and
delete." has been done, so we do the "delete" part.

Change-Id: Icd691aa8c3defdd68c306ad9eaf1379a8ba6ec0f
Reviewed-on: https://code.wireshark.org/review/37020
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-05-02 03:33:29 +00:00
Guy Harris 0e0f20bc7d wiretap: add a routine that adds a wtap_block_t for an IDB to a wtap.
Change-Id: I0a2e09bc3d1a858a304ded0c42be6bf09034812e
Reviewed-on: https://code.wireshark.org/review/37019
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-05-02 02:50:50 +00:00
Dario Lombardo c2d67c0928 wiretap: don't use memset where possible.
Change-Id: Id74764242ba13fb4ed58299a475096a64e5c6b5b
Reviewed-on: https://code.wireshark.org/review/36838
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-04-14 06:23:00 +00:00
Stig Bjørlykke 241967f46e erf: Use g_get_real_time() to get real time
Use g_get_real_time() to get real time because GTimeVal and g_get_current_time()
was deprecated in glib 2.62.

Change-Id: I78fee34e2f5b634c91c6420b01915cfc070f38a4
Reviewed-on: https://code.wireshark.org/review/34468
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-09-08 06:07:52 +00:00
Guy Harris 22e7952e06 HTTPS In Even More Places, update some links.
Fall back on the Wayback Machine for some links.

Change-Id: I6a44a2caaeb4fa521c2f08196e7c36069e3bb842
Reviewed-on: https://code.wireshark.org/review/34103
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-07-28 04:21:18 +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
Guy Harris 8a5b26efb1 Have wtap_read() fill in a wtap_rec and Buffer.
That makes it - and the routines that implement it - work more like the
seek-read routine.

Change-Id: I0cace2d0e4c9ebfc21ac98fd1af1ec70f60a240d
Reviewed-on: https://code.wireshark.org/review/32727
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-04-05 02:49:43 +00:00
Guy Harris a3de3fbec9 Treat erf_timestamp_t's as integral values.
That's what they are, and that's how other code in erf_open() treats
them; just use assignment to initialize prevts and to set prevts to ts.

Maybe this will keep the Clang static analyzer from calling prevts a
garbage value when compared with ts.

Change-Id: I2ee2376ced5c3efa6beab34276009a3177c94416
Reviewed-on: https://code.wireshark.org/review/32455
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-03-17 16:19:51 +00:00
Peter Wu 31aba351e2 wiretap: fix memleaks with wtap_rec::opt_comment
The memory ownership of wtap_rec::opt_comment was not clear. Users of
wtap were leaking memory (editcap.c). wtap readers were not sure about
freeing old comments (erf) or simply ignored memleaks (pcapng).

To fix this, ensure opt_comment is owned by wtap_rec and free it with
wtap_rec_cleanup. The erf issue was already addressed since
cf_get_packet_comment properly duplicates wth.opt_comment memory.

- wtap file formats (readers):
  - Should allocate memory for new comments.
  - Should free a comment from an earlier read before writing a new one.
- Users of wth:
  - Can only assume that opt_comment remains valid until the next read.
  - Can assume that wtap_dump does not modify the comment.
  - For random access (wtap_seek_read): should call wtap_rec_cleanup
    to free the comment.

The test_tshark_z_expert_comment and test_text2pcap_sip_pcapng tests now
pass when built with ASAN.

This change was created by carefully looking at all users opt
"opt_comment" and cf_get_packet_comment. Thanks to Vasil Velichkov for
an initial patch which helped validating this version.

Bug: 7515
Change-Id: If3152d1391e7e0d9860f04f3bc2ec41a1f6cc54b
Reviewed-on: https://code.wireshark.org/review/31713
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Vasil Velichkov <vvvelichkov@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-01-25 04:53:10 +00:00
Stephen Donnelly ead3d6b8c5 Relax ERF heuristic
Allow forward timestamp deltas up to 1 year, up from 7 days.
Surprisingly this was overly restrictive in some real cases.

Change-Id: I8a4bd1ca791b978aa5d2be40f7f8dd8e23db8837
Reviewed-on: https://code.wireshark.org/review/28882
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-07-31 04:32:17 +00:00
Pascal Quantin 30c0d7ba49 erf.c: fix compilation with gcc 8
erf.c:2562:9: error: this statement may fall through [-Werror=implicit-fallthrough=]

Change-Id: Ib516a689e078a9e1eea96d692ffbbaab398f2bcb
Reviewed-on: https://code.wireshark.org/review/27271
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-05-02 21:25:26 +00:00
Dario Lombardo fdd426e410 spdx: more licenses converted.
Change-Id: Ia1650bc02511f7bd47fb90be91b623177f05bcbd
Reviewed-on: https://code.wireshark.org/review/26337
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-03-09 04:48:20 +00:00
Guy Harris dc8bd7c3a9 Fix argument list in comment.
Oh, and change something up with which we have no evidence whether
Winston Churchill would put or not:

http://itre.cis.upenn.edu/~myl/languagelog/archives/001715.html

http://itre.cis.upenn.edu/~myl/languagelog/archives/001702.html

Change-Id: I7a76d564bdd481de2a56d32aa44c9dfe98a270f6
Reviewed-on: https://code.wireshark.org/review/25836
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-17 19:04:21 +00:00
Guy Harris 1f5f63f8ef Generalize wtap_pkthdr into a structure for packet and non-packet records.
Separate the stuff that any record could have from the stuff that only
particular record types have; put the latter into a union, and put all
that into a wtap_rec structure.

Add some record-type checks as necessary.

Change-Id: Id6b3486858f826fce4b096c59231f463e44bfaa2
Reviewed-on: https://code.wireshark.org/review/25696
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-09 00:29:51 +00:00
Anthony Coddington 3e14d3b440 ERF: Fix broken erf_open ethernet checking
Was copying 8 byte extension header instead of 2 byte ethernet padding subheader.
Introduced recently by I8ede5c733867ccc98ab2d470181d1e4a29ae5b49.

Change-Id: I95a8604ed6204dff33f1794601342e090f6b7eb3
Reviewed-on: https://code.wireshark.org/review/25410
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
2018-01-22 09:44:09 +00:00
Guy Harris af0f49e80d Use pcapng as the name of the file format.
At one point, I remember a discussion resulting in the official name of
the next-generation replacement for pcap format being changed to
"pcapng", with no hyphen.

Make Wireshark reflect that.

Change-Id: Ie66fb13a0fe3a8682143106dab601952e9154e2a
Reviewed-on: https://code.wireshark.org/review/25214
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-01-09 00:38:51 +00:00
Dario Lombardo f0681d0175 erf: remove redundant check (CID: 1159076).
This check has been alreay done in line 433: since then packet_size
is only decreased, then the check is redudant.

Change-Id: I8ede5c733867ccc98ab2d470181d1e4a29ae5b49
Reviewed-on: https://code.wireshark.org/review/25023
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2018-01-05 13:50:35 +00:00
Guy Harris 6d025eff1b Do the meta-tag stuff the same way in all three cases.
Undo most of the changes, but turn the return at the end of the default
case into a break.

Change-Id: I022b62a85254ff188f19fd3d7c3fe40b0789b3d2
Reviewed-on: https://code.wireshark.org/review/22695
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-07-18 04:34:42 +00:00
Guy Harris 5fd255424f Revert "Don't byte-swap an 1-byte value."
This reverts commit 74a2ae4aba.

No, that's just Coverity not understanding macros *again*, and thinking a particular expanded instance of a macro is the result of some human being silly rather than of the arguments being such that some computations can be elided at compile time.

Change-Id: I40f2ad8bf018b0df02d90ed0e272505be68dae7e
Reviewed-on: https://code.wireshark.org/review/22693
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-07-18 04:28:20 +00:00
Guy Harris 30f8ceebba Remove unnecessary test.
The default case ends with return, so the pointer won't be null by the
time out exit the case statement - either a non-default case is
processed and tag_ptr hasn't been set to null, or the default case is
processed and you return before getting there.

That also means we don't need to set tag_ptr to null in that case.

Fixes CIDs 1415436.

Change-Id: I21ada7a308d888b4cbb8557197a2e30bda118f44
Reviewed-on: https://code.wireshark.org/review/22691
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-07-18 01:58:08 +00:00