Commit Graph

182 Commits

Author SHA1 Message Date
Francois-Xavier Le Bail
12cded8329 PPP: Don't process further if protocol is unknown (-e option) 2022-07-03 16:07:07 +02:00
Francois-Xavier Le Bail
26231dad8b PPP: Add tests to avoid incorrectly re-entering ppp_hdlc() 2022-06-06 17:15:26 +02:00
Francois-Xavier Le Bail
68f6ee780d PPP: Change the pointer to packet data
Thus it can be used for debugging.
2022-03-07 15:32:07 +01:00
Denis Ovsienko
b5cbb4d2bb Lose some more unnecessary #include lines. [skip ci]
This trivial change compiles fine with GCC 7.5.0 on Linux and Clang
10.0.1 on FreeBSD, so let's not run the full round of CI this time.
2020-11-27 16:18:40 +00:00
Denis Ovsienko
ca71c84728 Fix some spelling. [skip ci] 2020-10-09 13:19:10 +01:00
Francois-Xavier Le Bail
aad6ac30ce Remove some now redundant ND_TCHECK_4() calls
ND_TCHECK_4(e).

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

Remove unused 'trunc' labels and associated codes.

Update the output of a test accordingly.
2020-09-08 14:14:13 +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
f5aa04085e Rename DLT_PPP_WITHDIRECTION to DLT_PPP_PPPD
In libpcap DLT_PPP_WITHDIRECTION was renamed to
DLT_LINUX_PPP_WITHDIRECTION and after to DLT_PPP_PPPD.

Rename other #defines to match.
2020-08-08 14:45:10 +02:00
Francois-Xavier Le Bail
5e9a51fdd5 CHDLC: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from the protocol name.
2020-08-06 16:27:24 +02:00
Francois-Xavier Le Bail
496c43c10b PPP: Update the link-layer dissectors to void functions
Moreover:
Remove trailing "_if" from some protocol names.
Update the outputs of two tests accordingly.
2020-08-06 16:25:52 +02:00
Guy Harris
2ba1be3523 Squelch some warnings.
Use ND_BYTES_AVAILABLE_AFTER() to calculate the number of bytes
remaining in the packet after a given pointer, rather than doing the
subtraction directly; that casts the result to a u_int (we don't handle
packets bigger than the maximum u_int value, so the difference between
the pointers will never be bigger than that value), so we don't have to
deal with it being a 64-bit value on LP64 or LLP64 systems.  (It also
makes it a bit clearer what we're doing).

Clean up some indentation while we're at it.
2020-05-25 02:02:34 -07:00
Guy Harris
e4add0b010 When un-escaping, don't allocate a too-large buffer.
The buffer should be big enough to hold the captured data, but it
doesn't need to be big enough to hold the entire on-the-network packet,
if we haven't captured all of it.
2020-04-18 14:04:59 -07: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
Francois-Xavier Le Bail
8534f3b7bf Use more HTTPS in URLs
[skip ci]
2019-08-19 15:49:21 +02:00
Guy Harris
07a7f33ba3 Fix some narrowing warnings on LP64/LLP64 platforms.
Add a ND_BYTES_AVAILABLE_AFTER() macro to find the number of bytes
available in the captured data, starting at the byte pointed to by the
argument.  It returns a u_int rather than a ptrdiff_t, so it'll be
32 bits on LP64 and LLP64 platforms as well as on ILP32 platforms.  Use
that macro.

Make size-of-buffer arguments size_t.

Cast some size_t and ptrdiff_t values to u_int or int.
2019-04-18 10:13:49 -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
f6156d7d1d PPP: Update two error messages
Update the output of a test accordingly.
2019-03-20 13:49:53 +01:00
Francois-Xavier Le Bail
d6ca6f1111 PPP: Fix two loops for undefined behavior at runtime
The errors were:
print-ppp.c:518:9: runtime error: unsigned integer overflow: 38 - 230
cannot be represented in type 'unsigned int'
print-ppp.c:1138:63: runtime error: unsigned integer overflow: 204 - 220
cannot be represented in type 'unsigned int'

Add a test case.
2019-03-18 23:04:07 +01:00
Francois-Xavier Le Bail
391ad4d31b PPP: Fix inaccurate variable names 2019-03-18 22:19:59 +01:00
Francois-Xavier Le Bail
79e7754fd2 Clean up whitespaces 2019-03-18 22:19:59 +01:00
Francois-Xavier Le Bail
3976533f2c Remove some useless tests
Because packet length (length) >= capture length (caplen).

(see the sanity checks in print.c, pretty_print_packet() function)
2018-09-14 18:04:38 +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
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
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
a53605c61b Add a malloc/free process with garbage collector
Use it in the PPP printer.
2018-03-14 13:59:26 +01:00
Francois-Xavier Le Bail
5eb4ffa131 Fix a typo 2018-03-10 14:49:07 +01:00
Francois-Xavier Le Bail
46f5203a8d Style update
Use parens around the sizeof argument, to match the style used elsewhere.
2018-02-06 20:01:55 +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
4c09b9584b PPP: Add a missing semicolon 2018-01-06 22:47:34 +01:00
Francois-Xavier Le Bail
ff1c209392 Fix some Coccinelle warnings "a \ character appears outside of a #define" 2018-01-04 13:26:39 +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
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
39c8c55aa9 Use more ND_TCHECK_n()/ND_TTEST_n() macros 2017-11-24 22:48:55 +01:00
Guy Harris
c511f4c3be Fix lcpconfopts[] bounds check.
The subscript is unsigned, so it's guaranteed to be >= 0.  It should
thus be checked against the size of the array, not against some other
2017-11-24 12:22:22 -08:00
Guy Harris
f9dbcc9615 More EXTRACT_U_1() and ND_TCHECK_n, clean up signedness, add length checks.
Add more EXTRACT_U_1() calls.

Use ND_TCHECK_n() where appropriate.

Use unsigned values wherever appropriate.

Make sure the claimed length of a control protocol packet doesn't go
past the claimed length of the on-the-wire packet.
2017-11-24 11:04:01 -08:00
Francois-Xavier Le Bail
8d3c7406c4 Use more the EXTRACT_U_1() macro to fetch a one-byte value (23/n)
Reminder: EXTRACT_8BITS is now EXTRACT_U_1.

In tok2str() calls (step 4).
2017-11-23 15:05:08 +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
Francois-Xavier Le Bail
3c8f3e13b0 Rename ND_TCHECK_/ND_TTEST_ macros
Now all the macros have a name meaning a count in bytes.

e.g.:
ND_TCHECK_32BITS -> ND_TCHECK_4
ND_TTEST_32BITS -> ND_TTEST_4
2017-11-22 21:58:44 +01:00
Francois-Xavier Le Bail
01cd3621f1 Use more the EXTRACT_8BITS() macro to fetch a one-byte value (22/n)
In ND_PRINT() macro calls, *p++.

Partial list.
2017-11-22 16:02:02 +01:00
Francois-Xavier Le Bail
6d78d5e47c Use more the EXTRACT_8BITS() macro to fetch a one-byte value (21/n)
In safeputchar() calls, *p++.
2017-11-22 13:52:05 +01:00
Francois-Xavier Le Bail
cb9b665059 Use more the EXTRACT_8BITS() macro to fetch a one-byte value (18/n)
Assignment, *(p op e)

Partial list.
2017-11-21 22:23:47 +01:00
Francois-Xavier Le Bail
a7a76012a1 Use more the EXTRACT_8BITS() macro to fetch a one-byte value (17/n)
Assignment, *p++ -> EXTRACT_8BITS(p); p++;

Partial list.
2017-11-21 20:30:12 +01:00