Commit Graph

56 Commits

Author SHA1 Message Date
Francois-Xavier Le Bail
1fabc59c13 Add the nd_print_protocol() function
Use the ndo->ndo_protocol field to print the protocol name.
2019-03-19 14:50:52 +01:00
Francois-Xavier Le Bail
9be45b2369 Use the ndo->ndo_protocol field instead of the protoname parameter
Moreover:
Fix a truncated string: "[!" is not the prefix for a truncated string.
Add two comments.
Clean up a whitespace.
2019-03-08 10:12:21 +01:00
Francois-Xavier Le Bail
e9439e9b71 Report 32-bit timestamps with uppermost bit set as "Error converting time"
In the ts_unix_print() function.

This change is a followup to commit 8e9fb1eb02.
2019-01-27 15:51:07 +01:00
Guy Harris
7df90fa2a2 Add, and use, macros to do locale-independent case mapping.
This means we get the same behavior in Turkish locales (where, if we
aren't in the C locale, we might get lower-case "i" mapped to upper-case
"I with dot" and upper-case "I" mapped to lower-case "i without dot),
and may also suppress some shortening warnings from MSVC.
2018-12-10 23:16:45 -08:00
Francois-Xavier Le Bail
77a49fcb6e Add the nd_print_invalid() function
It prints " (invalid)", used for malformed or corrupted packets.

Moreover:
Update CONTRIBUTING.
2018-09-11 13:09:05 +02:00
Francois-Xavier Le Bail
1d881d77df Report 32-bit timestamps with uppermost bit set as "Error converting time"
This is an update to packet header timestamps printing based on
Guy Harris's proposal.

Theses timestamps are outside the 1970-2038 range; This happens on some
fuzzed captures.

This will allow to have the same printing on Windows and UN*X.

Update needed before 2038.
2018-08-10 23:22:21 +02:00
Francois-Xavier Le Bail
cc190c1b58 Refactor printing the time fractional part ({micro|nano}seconds)
Add the ts_frac_print() function.

Avoid almost duplicate code.
2018-08-09 14:14:25 +02:00
Francois-Xavier Le Bail
d77ac851c7 Fix local time printing
Using seconds offset from GMT to local time to compute local time give
errors when printing times outside the same daylight saving time period.

Use the localtime() function for default and -tttt cases.
Use the gmtime() function for -ttt and -ttttt cases.

Rename ts_hmsfrac_print() to ts_date_hmsfrac_print().
Remove some variables now useless.
Update some comments.
2018-08-07 17:37:36 +02:00
Denis Ovsienko
9ea3e1b265 Fix some spelling in comments.
[skip ci]
2018-08-01 14:06:33 +01:00
Guy Harris
230e0b8577 Don't print timestamps to a buffer and then print the buffer.
Just directly print them.  This means:

	1) we don't have to worry about making a big enough buffer;

	2) we don't get annoying warnings about string truncation
	   due to invalid timestamp values;

	3) we use a constant string as a format, so that the compiler
	   can more easily do format string vs. format argument checks.
2018-07-29 19:16:42 -07:00
Guy Harris
fa48471019 Expand a comment. 2018-06-21 15:01:34 -07:00
Francois-Xavier Le Bail
4968a22f71 Add some EXTRACT_U_1() macro calls 2018-06-16 15:29:27 +02:00
Francois-Xavier Le Bail
7187e01f8f Add the fn_print_str() function
This function print a null-terminated string, filtering out non-printable
characters.
DON'T USE IT with a pointer on the packet buffer because there is no
truncation check. For this use, see the nd_printX() functions.
2018-05-18 23:05:01 +02:00
Francois-Xavier Le Bail
c45392de18 Add the nd_print_trunc() function
Use the ndo->ndo_protocol field to print a " [|protocol]" message.
2018-05-04 10:56:23 +02:00
Francois-Xavier Le Bail
e10fe19f45 Remove the safeputs() function
Use the nd_printzp() function instead.
2018-05-02 10:15:26 +02:00
Francois-Xavier Le Bail
0cced4fcdc Remove the safeputchar() function
Print the characters filtering out non-printable with fn_print_char().

Update the output of some tests accordingly.
2018-05-02 03:33:02 +02:00
Francois-Xavier Le Bail
3e3e6d2ef4 Rename the fn_printX() functions to nd_printX()
The functions are: nd_print, nd_printztn, nd_printn and nd_printzp.
Trying to make it clearer that they currently have to be used only on part
of the packet buffer.
Update some comments.
2018-04-30 13:35:06 +02:00
Francois-Xavier Le Bail
67f87a772e Use fn_print_char() to simplify some code 2018-02-13 19:53:37 +01:00
Guy Harris
c499612a7f Add nd_{v}snprintf() routines/wrappers.
Some versions of the MSVC runtime library have a non-C99-compliant
vsnprintf(), which we want to avoid.  On Windows, use snprintf() and
vsnprintf() for VS 2015 and later, where they both exist in
C99-compliant forms, and wrap _{v}snprintf_s() otherwise (they're
guaranteed to do the null termination that we want).
2018-01-29 15:48:55 -08:00
Francois-Xavier Le Bail
fe4ef2d22b Use the EXTRACT_U_1() macro in some utility functions 2018-01-28 14:18:51 +01:00
Guy Harris
fb2479d733 Always include <config.h> rather than "config.h".
This can prevent bizarre failures if, for example, you've done a
configuration in the top-level source directory, leaving behind one
config.h file, and then do an out-of-tree build in another directory,
with different configuration options.  This way, we always pick up the
same config.h, in the build directory.
2018-01-21 12:27:28 -08:00
Francois-Xavier Le Bail
513f782ae1 Use quoted include netdissect-stdinc.h instead of angle-bracketed one 2018-01-21 10:28:15 +01:00
Guy Harris
64677b0d78 Clean up signed vs. unsigned. 2018-01-11 11:52:30 -08:00
Francois-Xavier Le Bail
e2982e7f6f Update ND_PRINT() as a variadic macro 2018-01-07 13:36:41 +01:00
Francois-Xavier Le Bail
1a04b92e36 Use more the ND_TTEST_1() macro 2017-12-15 19:39:00 +01:00
Francois-Xavier Le Bail
5cea270318 Remove all storage class specifier 'register'
Let the compiler do the optimizations (or not) based on build options.

Avoid 'value has been optimized out' messages in gdb using '-O0'.
2017-12-13 19:17:47 +01:00
Francois-Xavier Le Bail
451ac4c753 Use more the ND_TCHECK_1() macro 2017-12-04 21:00:57 +01:00
Guy Harris
2b9bfa05b6 Check for unaligned memory access support at compile time.
Don't test at configure time; that doesn't work when cross-compiling and
may be a pain to do with CMake.
2017-10-16 01:39:10 -07:00
Guy Harris
a263db98fa Change some comments and variable names to reflect reality.
txtproto_print() isn't necessarily usable only for request/response
protocols, so don't speak as if it is.
2017-10-10 14:22:24 -07:00
Guy Harris
9f0730bee3 CVE-2017-13011/Properly check for buffer overflow in bittok2str_internal().
Also, make the buffer bigger.

This fixes a buffer overflow discovered by Bhargava Shastry,
SecT/TU Berlin.

Add a test using the capture file supplied by the reporter(s), modified
so the capture file won't be rejected as an invalid capture.
2017-09-13 12:25:44 +01:00
Guy Harris
21d702a136 CVE-2017-11541: In safeputs(), check the length before checking for a NUL terminator.
safeputs() doesn't do packet bounds checking of its own; it assumes that
the caller has checked the availability in the packet data of all maxlen
bytes of data.  This means we should check that we're within the
specified limit before looking at the byte.

This fixes a buffer over-read discovered by Kamil Frankowicz.

Add a test using the capture file supplied by the reporter(s).
2017-09-02 21:36:44 +01:00
Ulrich Windl
8cdb42601b Improve comment for tok2str() in util-print.c 2017-08-29 14:44:35 +01:00
Denis Ovsienko
3951a87cbe spell ASCII in uppercase 2017-08-10 09:52:46 +01:00
Hannes Gredler
ff8464bffd zero change: update Hannes Gredler's email 2017-07-28 17:44:12 +02:00
Guy Harris
8ca206d704 Use INT32_MIN to check for the smallest possible 32-bit signed value.
-2147483648 provokes warnings, for various reasons involving the
definition of a constant in C, the rules of picking the type of a
constant, and the rules for determining the type of an expression
involving an integral value and the - operator.  (Note that
-2147483648isn't a decimal-constant in C90 or C99, as a decimal-constant
can't contain a -.  Therefore, it's a constant expression, consisting of
the - operator applied to the constant 2147483648.)

So we use INT32_MIN, which should at least make an effort to avoid those
warnings.
2017-01-18 09:16:42 +01:00
Guy Harris
4e85180c53 Clean up signed_relts_print() some more.
If it's not < 0, it's not -2147483648; check for negative values first.

Don't calculate the value for -2147483648 by hand, print a - and then
have unsigned_relts_print() calculate the value for 2147483648.
2017-01-18 09:16:38 +01:00
Guy Harris
3de59bdfa2 Get rid of some duplicated code.
Have signed_relts_print() just call unsigned_relts_print() to do the
formatting, once it's ensured that the value is positive and printed a
leading minus sign if necessary.
2017-01-18 09:16:38 +01:00
Guy Harris
d07e352f5a CVE-2016-7993/Clean up relative time stamp printing.
Have separate routines for signed and unsigned relative time stamps.
Have the routine for signed time stamps handle the case of -2^31, where
you can't negate it and have the result fit in a 32-bit signed integer.

There are currently no users of the signed relative time stamp routine,
but it's there in case anybody needs it (and is passing 32-bit
quantitites, so that there's a risk that a packet might contain -2^31 as
the time stamp).

Fixes an array overflow found with American Fuzzy Lop by Hanno Böck.
2017-01-18 09:16:38 +01:00
Guy Harris
7bf069c251 CVE-2016-7983,7984/Don't use strchr() to scan packet data.
It can't be told to stop at the end of the packet data.  Add a
fn_printztn() that prints null-terminated strings, with a length check,
and which returns the number of bytes processed, or 0 if we ran out of
data.  That means it does the scanning we need, but safely.

Use it in the TFTP and BOOTP printers.

Fixes a heap overflow found with American Fuzzy Lop by Hanno Böck.
2017-01-18 09:16:37 +01:00
Guy Harris
62d52f2ea8 Squelch a signed array subscript warning.
As the string in question is passed as a constant from a printer, it
*shouldn't* contain any non-ASCII characters, but squelching the warning
is harmless and, on modern processors, a non-sign-extending byte load
shouldn't be any worse than a sign-extending byte load.
2016-08-07 15:35:54 -07:00
Francois-Xavier Le Bail
436ced3bd8 Change istr[] (for invalid string) to be global 2016-01-28 14:24:19 +01:00
Francois-Xavier Le Bail
4df36ab95d CDP: Filter out non-printable characters
Add a fn_print_char() to do filtering.
2015-11-09 16:29:32 +01:00
Guy Harris
11f73ad248 Don't require IPv6 library support in order to support IPv6 addresses.
Have our own routines to convert between IPv4/IPv6 addresses and
strings; that helps if, for example, we want to build binary versions of
tcpdump for Windows that can run both on NT 5 (W2K/WXP), which doesn't
have inet_ntop() or inet_pton(), and NT 6 (Vista/7/8/10), which do.  It
also means that we don't require IPv6 library support on UN*X to print
addresses (if somebody wants to build tcpdump for older UN*Xes lacking
IPv6 support in the system library or in add-on libraries).

Get rid of files in the missing directory that we don't need, and
various no-longer-necessary autoconf tests.
2015-09-17 14:56:44 -07:00
Guy Harris
1cdffe3d6b Include <ctype.h> to make sure we have all the isXXX() functions. 2015-09-14 14:50:39 -07:00
Francois-Xavier Le Bail
f5fe14663d libnetdissect code must include 'netdissect.h', not 'interface.h'
Moreover:
Remove netdissect.h include in interface.h
Move thiszone declaration in netdissect.h
Update a comment
2015-09-11 13:22:56 +02:00
Francois-Xavier Le Bail
99c91c3aec Rename 'tcpdump-stdinc.h' to 'netdissect-stdinc.h'
Get the full log via: git log --follow netdissect-stdinc.h
2015-09-10 08:50:40 +02:00
Francois-Xavier Le Bail
36c679753b Get rid of "tcpdump" in some libnetdissect codes 2015-09-08 18:01:26 +02:00
Denis Ovsienko
38bd521332 amend some comments in util-print.c
When I needed to print a string and didn't remember which of the three
functions fn_print(), fn_printn() and fn_printzp() was the right one
for the data, every time it would end up in reading through all of them
and forgetting the difference shortly after the commit.

Just having it explained in the comments should work better.
2015-09-05 21:11:53 +01:00
Francois-Xavier Le Bail
9d6b61de38 Fix display of timestamps with -ttt and -ttttt options
- Fix display of some nanoseconds timestamps
For example, bad print 00:-16:-2.000851566 is now 00:00:00.037851566

- Fix display of timestamp of a packet when it is lower than previous one
For example, bad print 00:00:-1.000999790 is now -00:00:00.000000210
2015-07-02 19:14:49 +02:00
Denis Ovsienko
0938876cd1 refine tok2str() buffer use
Switch RRCP and BGP functions from tok2strbuf() to tok2str() to avoid
unnecessary local buffer management. The latter function does it in a
way to allow up to 4 calls to itself from printf(). After that
tok2strbuf() remains used by tok2str() only and can be refined later.

Remove a duplicate macro and place the remaining definition into the
right file.
2015-06-29 15:53:56 +01:00