Commit Graph

160 Commits

Author SHA1 Message Date
Francois-Xavier Le Bail
2800b89683 ISAKMP: Use GET_U_1() to replace a direct dereference
Moreover:
Remove an unnecessary cast and an & operator.
2022-02-19 10:40:35 +01:00
Francois-Xavier Le Bail
794a259a33 Put a space between type and '*' in pointer declarators (style) 2021-12-30 20:23:13 +01:00
Francois-Xavier Le Bail
6288c273b6 Remove useless 'return' at end of void functions (style) 2020-09-28 17:04:08 +02:00
Denis Ovsienko
51e180c4fb Remove 96 assorted ND_TCHECK calls.
Remove a number of instances that do not match common patterns and have
the only substantial effect on the code flow that a truncated packet
triggers "goto trunc" instead of longjmp(). (In a few cases this change
can increase the number of fields printed before giving up.)
2020-09-08 05:04:58 +01:00
Francois-Xavier Le Bail
abc8c2d61c Remove many (762) now redundant ND_TCHECK_n() calls
ND_TCHECK_n(e), n in { 1, 2, 3, 4, 8 }.

They are redundant because they are followed by a GET_.*_n(e) call,
same n, same e, which do the bounds check.

Remove unused 'trunc' labels and most associated codes.

Update the outputs of some tests accordingly.
2020-09-06 20:22:29 +02:00
Francois-Xavier Le Bail
8c88f9f54a ESP: Rename two printers
Rename esp_print_decodesecret() to esp_decodesecret_print() and
esp_print_decrypt_buffer_by_ikev2() to esp_decrypt_buffer_by_ikev2_print()
with _print suffix like in most similar cases.
2020-03-08 13:41:07 +01:00
Guy Harris
306c2a0384 More bounds checking when fetching addresses and converting to strings.
Replace more calls to ipaddr_string()/ip6addr_string() with calls to
GET_IPADDR_STRING()/GET_IP6ADDR_STRING() macros performing bounds
checking.

Add similar bounds-checking inline functions and macros to wrap
linkaddr_string(), etheraddr_string(), and isonsap_string() and convert
calls to them to use the macros as well.

Shuffle the inline functions in addrtoname.h around a bit, so that the
inline functions, external declarations, and macros are all in the same
order.
2020-01-19 19:55:38 -08:00
Guy Harris
9a6a650241 Don't use <ctype.h> macros.
Some of them are locale-dependent, and all of them run the risk of
failing if you hand them a char with the 8th bit set.

Move our replacements to a new netdissect-ctype.h file, and, for the
ones that check for particular character types, add _ASCII to the name,
to indicate that only ASCII characters pass the check.  Do the same for
the ones that map between cases, to indicate that they only map ASCII
letters.

For isspace(), explicitly check for the characters we care about, to
make it clearer what we're doing.
2019-09-01 16:11:32 -07:00
Guy Harris
1ed63b5d06 Remove more old-compiler compensation.
We require an environment with a C99-compatible snprintf(), so we don't
need to work around older implementations.  Make the configuration
process fail if we don't have snprintf() and vsnprintf().

We require at least VS 2015, so we don't have to check for _MSC_VER >=
1400.  Make the build fail if we don't have at least VS 2015.

We apparently do, however, have to use __inline, as the VS 2015
documentation doesn't meaning plain old "inline".  Update a comment.
2019-08-08 23:21:35 -07:00
Francois-Xavier Le Bail
0c9cfdcb0d Use nd_ipv6 rather than struct in6_addr 2019-06-10 15:32:20 +02:00
Francois-Xavier Le Bail
6fc5b4200b Use nd_ipv4 rather than struct in_addr 2019-06-10 14:14:46 +02:00
Guy Harris
b7b72b7c63 Treat the length field in an Ethernet header as such.
If we have an Ethernet packet where the last 2 octets of the header are
a length rather than an Ethernet type, and it's less than the remaining
length of the packet, shorten the length and captured length, update the
snapshot end.

Turn the buffer stack into a "packet information" stack, so that, if we
*do* update the snapshot end, we push the old end onto the stack, and
pop it off as soon as we're done dissecting the Ethernet packet, in case
there's more data in the packet after the Ethernet packet.

Use the stack when we use the IPv4 and IPv6 length fields as well.
2019-04-22 23:49:02 -07:00
Guy Harris
6da51b3ec9 Introduce a buffer stack, and use it for ESP decryption.
If a dissector has to process its input - decryption, decompression,
etc. - rather than dissect the raw input, it should push the processed
input onto the buffer stack.  As soon as the dissection is done, the
stack should be popped, to free the buffer into which the processing was
done, and restore the "pointer to packet data" and "pointer to end of
packet data" members of the netdissect_options structure, so the code
can go back to dissecting the original data.

The stack will get everything popped off it when dissection is done.

Use this mechanism in the ESP decryption code rather than scribbling on
top of the input packet data.
2019-03-30 19:26:06 -07:00
Guy Harris
48644533f2 Have esp_print() handle printing its payload.
That cleans things up a bit, including removing some duplicate code.

Clean up some other things, and add a length check, while we're at it.
2019-03-28 11:45:43 -07:00
Guy Harris
202051bb55 Put IPv4/IPv6 protocol demultiplexing into a common routine.
That means less duplication of functionality - and less chance that
XXX-over-IPv4 will be handled but XXX-over-IPv6 won't be handled, or
*vice versa*.  (CARP and VRRP were being handled over IPv4 but not over
IPv6; this fixes that.)
2019-03-27 19:58:26 -07:00
Guy Harris
69128db28e Fix typo in comment.
[skip ci]
2019-03-26 19:52:36 -07:00
Francois-Xavier Le Bail
ee68aa3646 Use the new GET_ macros instead of the EXTRACT_ ones
The exceptions are currently:
Some EXTRACT_ in print-juniper.c, not used on packet buffer pointer.
An EXTRACT_BE_U_3 in addrtoname.c, not always used on packet buffer
pointer.
2019-03-26 21:06:24 +01:00
Francois-Xavier Le Bail
1af20c3adc Add the ndo parameter to some functions
This parameter will be needed at the next step.
2019-03-26 21:06:23 +01:00
Francois-Xavier Le Bail
bcbe2cd035 ISAKMP: Simplify an expression 2019-02-27 20:31:02 +01:00
Francois-Xavier Le Bail
b9ac2f3feb Clean up whitespaces 2019-02-27 20:13:59 +01:00
Francois-Xavier Le Bail
46efa1bc47 Fix spaces 2018-09-03 15:18:19 +02:00
Francois-Xavier Le Bail
4dee61760d Add more nd_print_trunc() calls
Update the output of some tests accordingly.
2018-06-06 18:12:42 +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
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
7127f07f1f Remove a no more used 'volatile' qualifier 2018-02-23 10:21:17 +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
95e7cd03e6 Don't decrement an unsigned zero value below zero.
In fact, don't waste time incrementing the pointer or decrementing the
count until we know that we're going to go through another trip through
the loop.  (This isn't a PDP-11 and probably isn't a VAX or 68k, so *p++
isn't going to be done by an addressing mode.)

This should fix an undefined-behavior warning.
2018-02-01 14:16:11 -08:00
Francois-Xavier Le Bail
0ee15606e2 Remove unneeded '&' when getting a pointer to a nd_ipv6 type 2018-01-31 16:43:50 +01:00
Francois-Xavier Le Bail
5922b80797 Remove unneeded '&' when getting a pointer to a nd_ipv4 type 2018-01-31 16:43:50 +01:00
Guy Harris
3db38df8ed Use nd_ipv6 rather than struct in6_addr in packet-layout structures.
Also, use it, and nd_ipv4, in sizeof() operations.
2018-01-30 17:29:33 -08: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
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
Francois-Xavier Le Bail
e2982e7f6f Update ND_PRINT() as a variadic macro 2018-01-07 13:36:41 +01:00
Francois-Xavier Le Bail
d526e47658 Use ND_TTEST_SIZE()/ND_TCHECK_SIZE() macros (1/n) 2018-01-03 21:32:07 +01:00
Guy Harris
a1b2cce62e Put a variable only used if we have libcrypto under HAVE_LIBCRYPTO. 2017-12-30 13:08:43 -08:00
Guy Harris
5fc11e8d2f Fix decryption code path.
Thanks for making this hard to test on macOS, Apple.  You *could*
continue to ship the headers for libcrypto even if you want to get
everybody to use your Shiny New SSL code rather than Boring Old OpenSSL
- just don't ship the headers for the SSL library - but nooooooo.
2017-12-17 23:45:14 -08:00
Guy Harris
195a4cfd9d Clean up ISAKMP dissection, use nd_ types and EXTRACT_ macros.
Add some RFC numbers.

Structures with nd_ types work well if you overlay them on top of the
packet buffer, but not as well with an on-the-stack structure into which
you copy from the packet, which is ugly if you do *both* with the same
structure.  Use overlaying uniformly.

Add EXTRACT_ macros as necessary for the nd_ types.

Make stuff unsigned if it's appropriate.

Use unsigned formats for unsigned values.

A number of routines are passed the length of a payload, so they don't
have to re-fetch that length themselves.  That length has been
pre-checked to make sure it's big enough for the payload header; note
that in comments.
2017-12-17 21:49:46 -08: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
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
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
61c422a88c Use more the EXTRACT_U_1() macro (43/n)
In: if (... p[n] ...) ...
2017-12-03 13:35:26 +01:00
Francois-Xavier Le Bail
a5bb53dd74 Simplify some expressions 2017-12-03 11:13:27 +01:00
Francois-Xavier Le Bail
d7b497cac7 Use more the EXTRACT_U_1() macro (40/n)
In some macros and functions calls.
p[n], unsigned char *p.
2017-12-01 22:35:28 +01:00
Francois-Xavier Le Bail
505cd1fe15 Use more the EXTRACT_U_1() macro (39/n)
In some macros and functions call, p[n]
2017-12-01 15:48:41 +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
f68c3e3ec0 Use pointer expressions like in most similar cases 2017-11-23 12:23:32 +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