Commit Graph

23 Commits

Author SHA1 Message Date
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
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 436278747e Reset the terminal color if we're ^C'ed when reading a capture.
Catch signals/ctrl events when we're reading a capture, and stop reading
if we get one of those.  When we close a print stream, restore the color
as appropriate.

Change-Id: I3dd936964560fb3902befe0fd2e961f80437ca72
Ping-Bug: 15659
Reviewed-on: https://code.wireshark.org/review/32716
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-04-04 18:53:32 +00:00
Guy Harris 505c3187a4 Clean up color handling.
For Windows:

Don't use ws_isatty() - which is a wrapper around _isatty() - to
determine whether the output is to a Windows console or not; it returns
a non-zero value for *any* character device, not just a console.
Instead, use a console API; if it succeeds, it's a console, otherwise it
isn't.

If we're writing to a console, and the
ENABLE_VIRTUAL_TERMINAL_PROCESSING flag is set, or it isn't set but we
can set it, assume the console supports the escape sequences that
request 24-bit color, and use them.

For UN*X:

We can isatty() to determine if the output is to a terminal, as it
doesn't check for character special files, it specifically checks for
terminals (which, in practice, means "device that supports one of the
ioctls to get terminal modes" in most if not all cases; that covers
serial lines, pseudo-ttys, and perhaps some other devices).

Only use the 24-bit color escape sequences if the COLORTERM environment
variable is set to "truecolor" or "24bit".

Bug: 15659
Change-Id: I673667b86bd6b2ab48c06e00ed16b537d6723453
Reviewed-on: https://code.wireshark.org/review/32689
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-04-03 05:59:51 +00:00
Guy Harris 2dfb2067d8 On Windows, don't do console stuff unless we're on a terminal.
Clean up some code where that was already the case, to make it clearer
that it is the case.

Make that be the case in print_stream_text_alloc().

Change-Id: If6ef1ded9dad94ffaccb5d214f70c7e4d0844e8a
Reviewed-on: https://code.wireshark.org/review/32660
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-04-01 07:19:07 +00:00
Guy Harris 8b0615de3b Only put generic values into the print_stream_t structure.
Put values used only by particular subclasses into the subclass data
structure.

Change-Id: Ibb995ebf18ba24449467e932084fbeef03ad1abf
Reviewed-on: https://code.wireshark.org/review/32653
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-04-01 01:41:56 +00:00
Guy Harris 85838c124a I misread the Microsoft documentation; fix the comment.
Change-Id: I5d751680fe038b40a5d982a28ac61a62baec116f
Reviewed-on: https://code.wireshark.org/review/32625
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-03-30 03:27:52 +00:00
Guy Harris 1d984e598e Update a comment.
Update a URL, raise questions about *which* escape sequences give you
24-bit color on Windows.

Change-Id: Ic88e29de1049824210be2857b75409a5ffa1585e
Reviewed-on: https://code.wireshark.org/review/32624
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-03-30 02:21:24 +00:00
Dario Lombardo 8cd389e161 replace SPDX identifier GPL-2.0+ with GPL-2.0-or-later.
The first is deprecated, as per https://spdx.org/licenses/.

Change-Id: I8e21e1d32d09b8b94b93a2dc9fbdde5ffeba6bed
Reviewed-on: https://code.wireshark.org/review/25661
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08 14:57:36 +00:00
Guy Harris 69e1bdd62b More information on the Windows Console and escape sequences.
Change-Id: I8a57053658ef17d28c28c458e8fe5350332a953b
Reviewed-on: https://code.wireshark.org/review/25201
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-01-08 21:09:39 +00:00
Guy Harris 0655931f60 Point to the MSDN blog post about 24-bit color support in cmd.exe.
Change-Id: Ic23f1d6ee35333ab4775970455f71315925f4cc6
Reviewed-on: https://code.wireshark.org/review/25200
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-01-08 20:51:14 +00:00
Gerald Combs a6a5b552ec Update a comment about Windows Console color support.
Change-Id: I39171a3c95ca48a39fbbc90ceadb9b1436f2402c
Reviewed-on: https://code.wireshark.org/review/25196
Reviewed-by: Michael Mann <mmann78@netscape.net>
2018-01-08 19:45:50 +00:00
Gerald Combs a65391f901 TShark: Fix color handling on Windows.
Use SetConsoleTextAttribute to reset our colors on Windows. Update the
release notes and man page.

Change-Id: I2bc309787f9c2331324503092bd1c9ae6360eb55
Reviewed-on: https://code.wireshark.org/review/25170
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-01-06 14:30:45 +00:00
Robert Sauter ac20605634 print_stream.c: Fix compile error on Windows regression
Put closing #endif inside function body.

Regression by https://code.wireshark.org/review/22086/

Change-Id: I6f49dd45598c77c0a10c62f18f85fd7b99aba975
Reviewed-on: https://code.wireshark.org/review/22088
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-06-12 06:01:24 +00:00
Guy Harris f4dd096afb Add a big comment about the ISO 8613-6/T.416 SGR support.
Also, the signature of print_color_escape() must be the same on Windows
and UN*X; put the function body, but not the opening part of the
definition, inside #ifdefs.

Change-Id: I060e01d3280bfc4596a852211f5ab3c58d1e8642
Reviewed-on: https://code.wireshark.org/review/22086
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-11 22:18:13 +00:00
Dave Goodell affa6f18c8 print_stream: add a new print_line_color() method
This new interface allows printing a line with specified foreground and
background colors.  The implementation avoids printing escape sequences
if the output stream is not a TTY and note that escape sequences are
ignored on Windows.

This initial implementation relies on relatively modern 24-bit color
support which is present in many terminal emulators but may not always
display properly on older or simpler emulators. Windows coloring is
handled with SetConsoleTextAttribute, which offers a "1-bit" color
experience (but it's better than nothing)

This commit is a precursor to adding additional coloring to tshark.

Bug: 5158
Change-Id: Ib2b9d800095a065a4bb60abe0550862cda5539ec
Reviewed-on: https://code.wireshark.org/review/21324
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-06-11 13:36:06 +00:00
Dario Lombardo a29fe9d76a print_stream: free memory on exit.
Change-Id: I6c4acaa9026cfdf1d4230c28c30bccfb6c025cef
Reviewed-on: https://code.wireshark.org/review/19920
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: Dario Lombardo <lomato@gmail.com>
2017-02-27 13:25:26 +00:00
Gerald Combs cd1ddf6ef5 Speed up print_line_text.
isatty adds a small delay, at least on OS X. Call it only when we
allocate a stream. Do the same for our codeset check.

Change-Id: Id3a20059dbc9cf7d5db16d8d238d038b9de0ebf2
Reviewed-on: https://code.wireshark.org/review/16222
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2016-06-30 19:21:04 +00:00
Gerald Combs bda417a54f Use g_get_charset instead of g_get_codeset.
From Guy via
https://www.wireshark.org/lists/wireshark-dev/201605/msg00027.html

Change-Id: I7884cecb6cd87f474ecc3f84253797fe57f62487
Reviewed-on: https://code.wireshark.org/review/15421
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-05-14 07:59:46 +00:00
Gerald Combs ae4a912af0 TShark: Convert TTY output.
If we detect that we're writing to a TTY and that it doesn't support
UTF-8, convert our output to the current code page on UNIX/Linux or
to UTF-16LE on Windows. This helps to ensure that we don't fill users'
screens with mojibake, along with scrubbing invalid output.

Add a note about our output behavior to the TShark man page. Add a note
about the glyphs we should and shouldn't be using to utf8_entities.h.

Bug: 12393

Change-Id: I52b6dd240173b80ffb6d35b5950a46a565c97ce8
Reviewed-on: https://code.wireshark.org/review/15277
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Graham Bloice <graham.bloice@trihedral.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-05-09 04:11:29 +00:00
Bill Meier 454fd6e9eb Add "Editor modelines"; Adjust whitespace as needed.
Change-Id: Ic5a5acb0f36d3aa144edbfb1ae71097b18426db4
Reviewed-on: https://code.wireshark.org/review/6216
Reviewed-by: Bill Meier <wmeier@newsguy.com>
2015-01-02 00:49:09 +00:00
Guy Harris 6e1214c4df Fix comments.
Change-Id: I3b7340939b8204102bfc7e2e7d83f4d978cf7bad
Reviewed-on: https://code.wireshark.org/review/5437
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-11-22 03:32:58 +00:00
Guy Harris 7d7fc47a2a Split the low-level print stream code into a separate file.
Put the low-level print stream code from epan/print.c into
epan/print_stream.c, leaving the higher-level stuff in print.c

Change-Id: Iae961f168ec655a29f434257b1af0937fca9f025
Reviewed-on: https://code.wireshark.org/review/5436
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-11-22 03:24:17 +00:00