Commit Graph

24 Commits

Author SHA1 Message Date
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
Francois-Xavier Le Bail
22d4afb88a Fix display of nanoseconds timestamps with -tt option (GH issue 466)
Add 'ts_unix_format' function.
2015-06-19 10:35:18 +02:00
Francois-Xavier Le Bail
6632565511 Fix a non-reentrant code in a function
Delete the 'static char buf' array in ts_format().
buf is now a parameter of ts_format().
Moreover:
Decrease a too long string.
Fix a space in a comment.
2015-06-19 09:28:47 +02:00
Guy Harris
3dd9240cc3 Do case-insensitive comparisons assuming ASCII strings.
Do the case-insensitive comparisons in a locale-independent fashion that
only maps ASCII letters, in the standard English-language fashion; that
way, we don't get bitten by, for example, Turkish having separate "i
with dot" and "i without dot" letters, with lower-case "i with dot" being
mapped to upper-case "I with dot" rather than being mapped to "I".
2015-06-11 15:47:44 -07:00
Guy Harris
30b028f9da Use unsigned values in tok2str and bittok2str routines.
This prevents the compiler issue mentioned in GitHub issue #451, and
also cleans up some other signed vs. unsigned stuff.

While we're at it, clean up bittok2str_internal() (just pass it the
separator string, not a Boolean value that's tested to choose the
separator string), and print unknown arguments to the bittok2str
routines in hex, not decimal.
2015-04-18 19:56:49 -07:00
Brooks Davis
115a063589 Disentangle packet dissection functionally in tcpdump from the internal
libnetdissect.  This greatly narrows the public interface and allows
libnetdissect to be more easily sandboxed.
2015-04-15 18:52:33 +00:00
Brooks Davis
7f17c777dc Move functions in util.c that are used in the dissectors into a
util-print.c.  The remaining functions are used only in the frontend.
2015-04-15 18:52:33 +00:00