Commit Graph

195 Commits

Author SHA1 Message Date
Francois-Xavier Le Bail
d80d56eec3 IP: Simplify an expression 2018-09-22 12:46:36 +02:00
Francois-Xavier Le Bail
4f1cc2f3e3 Add a nd_print_trunc() call 2018-09-13 21:42:20 +02: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
25621613e3 IP: Stop decoding when truncation occurs in options
We just keep the checksum control.
2018-06-05 09:27:00 +02:00
Francois-Xavier Le Bail
1767655a9e IP: Print clearer when the version is invalid
Update the output of some tests accordingly.
2018-06-03 12:16:38 +02:00
Francois-Xavier Le Bail
1889ef324c Remove some spaces (style) 2018-05-10 17:40:20 +02:00
Francois-Xavier Le Bail
ba8936b39b Print truncations with nd_print_trunc() instead of tstr[] strings
Remove the tstr[] strings.
Update the output of some tests accordingly.

Moreover:
Add or update some ndo_protocol fields.
2018-05-04 13:47:49 +02:00
Francois-Xavier Le Bail
56e6581c34 Remove useless comments 2018-03-19 15:16:32 +01:00
Francois-Xavier Le Bail
546558eabd Add the ndo_protocol field in the netdissect_options structure
Update this field in printer entry functions.
It will be used for some printings.
2018-03-16 19:44:47 +01:00
Francois-Xavier Le Bail
1290a0a5cc Remove a trailing space 2018-03-09 20:57:55 +01:00
Francois-Xavier Le Bail
ef987f720c Rename some printer functions to *_print
Moreover:
Fix spaces.
2018-02-22 14:19:42 +01:00
Guy Harris
0dad1934af Have ip{6}addr_string take a u_char * as the second argument.
Fix warnings that introduces.
2018-01-31 00:43:45 -08: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
83046fe183 Remove unneeded '&' when getting a pointer to an nd_uintN_t type 2018-01-08 18:40:34 +01:00
Francois-Xavier Le Bail
b3158f9a05 IP: Remove space printing at end of line
Update the output of some tests accordingly.
2018-01-07 23:38:16 +01:00
Francois-Xavier Le Bail
e133c5e197 IP: Use more ND_TCHECK_n() macros 2018-01-07 23:30:37 +01: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
4a28df231d Use ND_TTEST_SIZE()/ND_TCHECK_SIZE() macros (2/n) 2018-01-03 22:23:30 +01:00
Guy Harris
b347189ca6 Add EXTRACT_ macros/functions for IPv4 addresses, get rid of structure wrappers.
Add EXTRACT_IPV4_TO_HOST_ORDER() and EXTRACT_IPV4_TO_NETWORK_ORDER();
the former extracts a possibly-unaligned IPv4 address, in network byte
order, returning a uint32_t in host byte order, and the latter extracts
a possibly-unaligned IPv4 address, in network byte order, returning a
uint32_t in *network* byte order.  Some APIs take an address in network
byte order, and some operations are more easily done in host byte order,
so both are useful.

Remove the structure wrappers around nd_ipv4 and nd_ipv6; that makes it
easier to pass variables of those types to functions/macros that take a
byte pointer as an argument (because they might be used either with
pointers to structure members or raw buffer pointers), and the structure
probably wouldn't do much to prevent people from using EXTRACT_BE_U_4()
when they really want to extract the value in *network* byte order;
using the above EXTRACT_IPV4_ calls should do more to encourage that.
2017-12-20 01:07:48 -08: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
84ef17ac0e Replace ND_TTEST2()/ND_TCHECK2() macros by macros using pointers (1/n)
ND_TTEST2(var, l)  -> ND_TTEST_LEN(p, l)
ND_TCHECK2(var, l) -> ND_TCHECK_LEN(p, l)
2017-12-11 22:11:01 +01:00
Guy Harris
3f3f2505f2 Make nd_uint8_t and nd_int8_t arrays, to catch direct references.
This catches direct references, so we can change them to use EXTRACT_U_1
or EXTRACT_S_1.

Also, change some structures to use the nd_ types that weren't already
using them.

Then make the appropriate EXTRACT_{U,S}_1() changes.
2017-12-10 16:23:34 -08:00
Francois-Xavier Le Bail
6bb65331a5 Use more the EXTRACT_U_1() macro (53/n)
Assignment, p[n], (more)
2017-12-10 11:40:35 +01:00
Francois-Xavier Le Bail
07ac438e08 Use more the EXTRACT_U_1() macro (52/n)
Assignment, p[n]
2017-12-09 14:05:25 +01:00
Francois-Xavier Le Bail
ef3437c081 Use more the EXTRACT_U_1() macro (50/n) 2017-12-09 10:17:18 +01:00
Francois-Xavier Le Bail
3a7639e545 Use more the EXTRACT_U_1() macro (49/n)
Assignment, *(p)
2017-12-09 09:56:29 +01:00
Francois-Xavier Le Bail
451ac4c753 Use more the ND_TCHECK_1() macro 2017-12-04 21:00:57 +01:00
Francois-Xavier Le Bail
00b189d27c Use more the ND_TCHECK_1() macro 2017-12-04 17:50:29 +01:00
Francois-Xavier Le Bail
4166458a2a Use more the EXTRACT_U_1() macro (46/n)
In: if (... p[n] ...) ...
2017-12-03 21:51:36 +01:00
Francois-Xavier Le Bail
10a52254ae Use more the EXTRACT_U_1() macro (44/n)
In: switch (... p[n] ...) ...
2017-12-03 14:00:15 +01:00
Francois-Xavier Le Bail
1a90fd99d2 Use more the EXTRACT_U_1() macro (28/n)
In ND_PRINT() macro call(s) (step 7).

p[n] ...
2017-11-26 15:44:43 +01:00
Francois-Xavier Le Bail
575188b5bf Use pointer expressions like in most similar cases 2017-11-25 18:21:18 +01:00
Francois-Xavier Le Bail
39c8c55aa9 Use more ND_TCHECK_n()/ND_TTEST_n() macros 2017-11-24 22:48:55 +01:00
Francois-Xavier Le Bail
66e9f3970c Use more the EXTRACT_U_1() macro to fetch a one-byte value (25/n)
In ND_PRINT() macro call (step 4).

(*p op1 e1) op2 e2
2017-11-23 20:23:59 +01:00
Francois-Xavier Le Bail
da20bc56d6 Rename EXTRACT_ macros
Now all the macros have a name meaning a count in bytes.

With _S_: signed, _U_: unsigned

e.g.:
EXTRACT_BE_32BITS -> EXTRACT_BE_U_4
EXTRACT_LE_32BITS -> EXTRACT_LE_U_4
...
EXTRACT_BE_INT32 -> EXTRACT_BE_S_4

and have:
EXTRACT_8BITS -> EXTRACT_U_1
EXTRACT_INT8  -> EXTRACT_S_1
2017-11-22 23:54:09 +01:00
Guy Harris
c0679b38a3 More EXTRACT_8BITS() and other cleanups.
Get rid of casts to (int) that aren't needed or wanted.

If a field is unsigned, use an unsigned variable for it, print it with
%u, not %d, and don't cast it to int.

Replace a static variable in print-dvmrp.c with a local variable in
dvmrp_print() and a parameter to print_neighbors2().
2017-11-22 10:15:49 -08:00
Francois-Xavier Le Bail
93bee24026 Use pointer expressions like in most similar cases 2017-11-20 22:58:59 +01:00
Francois-Xavier Le Bail
577621026d Rename EXTRACT_nBITS() macros to EXTRACT_BE_nBITS()
It indicates clearly that these macros are used to extract big-endian
integral values.
2017-11-18 13:56:40 +01:00
Guy Harris
2c2cfbd2b7 CVE-2017-13037/IP: Add bounds checks when printing time stamp options.
This fixes a buffer over-read 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
eee0b04bcf CVE-2017-13022/IP: Add bounds checks to ip_printroute().
This fixes a buffer over-read 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
Denis Ovsienko
b3fb6a6c61 Use a table instead of getprotobynumber().
On Linux getprotobynumber() returns different results for the same
argument depending on the contents of /etc/protocols at runtime
(expectedly but gets in the way of reproducible test cases). On FreeBSD
it returns results that are irrelevant of the contents of /etc/protocols
at runtime (unexpectedly). Other implementations exist and may expose
interesting properties too. And if the host uses LDAP instead of
/etc/protocols for name services, a call to that function may cause LDAP
handle the request. All of the above is not right for the specific task
of network protocols decoding, which needs to be fast and deterministic.

As the protocol number space is just 8-bit, add a 256-element array of
strings/NULLs for the translation and a wrapper function around it for
index range enforcement. Change the code to use the new function instead
of getprotobynumber().

Fix a typo while at it.
2017-08-27 14:19:25 +01:00
Guy Harris
406b0e3e92 Stop processing IPPROTO_ values once we hit IPPROTO_IPCOMP.
It's not like, for example, AH or ESP, where, following the header for
that protocol, there's another protocol with its own payload.
2017-01-18 09:16:37 +01:00
Guy Harris
e8a7716282 CVE-2016-7974/Don't try to dissect something with other than 4 as the IP version.
Bad Things could happen, e.g. the dissector we call thinking it's been
handed an IPv6 header when we haven't handed it anything that large.

Fixes a heap overflow found with American Fuzzy Lop by Hanno Böck.

Update some .out files to correspond to that change.
2017-01-18 09:16:37 +01:00
Guy Harris
3998839886 CVE-2016-7974/Add an additional bounds check.
Fixes a heap overflow found with American Fuzzy Lop by Hanno Böck.
2017-01-18 09:16:35 +01:00
Guy Harris
98f666f243 CVE-2016-7974/Check before fetching the IP protocol version.
Fixes a heap overflow found with American Fuzzy Lop by Hanno Böck.
2017-01-18 09:16:35 +01:00
Guy Harris
17a3c28858 Clean up the switch statement for the ToS.
Put in an explicit "do nothing" clause for a value of 0, to make it
clearer that we handle that case.

Put a break after each case.

Add blank lines between cases.
2016-12-10 11:04:05 -08:00
Tony Xu
eff98c50c6 No need test 2016-12-10 18:45:37 +08:00