Commit Graph

36 Commits

Author SHA1 Message Date
Francois-Xavier Le Bail
fb59931bfc Update ND_BYTES_BETWEEN() macro for better accuracy
Update the macro that computes how many bytes are present, starting
at the first argument and running up to (but not including) the second
argument, and returns that as a u_int (cutting it to 32 bits on LP64
and LLP64 platforms).

This reverses, for reasons of readability, the order of the arguments
which was based on old SMB's PTR_DIFF().

With this change the number of bytes "between" given by the macro is 0
when the first argument is greater than or equal to the second argument.

Update ND_BYTES_AVAILABLE_AFTER() accordingly.

This is a follow-up to f9c2c905b1.
2023-06-12 16:11:12 +02:00
Francois-Xavier Le Bail
68218acff7 RESP: Remove an unnecessary test
Moreover:
Remove an unneeded variable.
2022-03-06 10:33:40 +01:00
Francois-Xavier Le Bail
9fe73b290d RESP: Fix an invalid check
Fix this cppcheck warning:
print-resp.c:215:22: warning: Checking if unsigned expression 'length'
is less than zero. [unsignedLessThanZero]
    if(!bp || length <= 0)
                     ^
2022-03-02 21:49:17 +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
9169e4e194 Include <string.h> only if required. 2020-10-17 17:55:37 +01:00
Denis Ovsienko
4ecc5682ee RESP: Lose a duplicate forward declaration. 2020-10-13 11:32:32 +01: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
5807acd8ee RESP: Use GET_U_1() to replace direct dereferences
Moreover:
Fix spaces
2020-08-10 17:18:42 +02:00
Francois-Xavier Le Bail
8534f3b7bf Use more HTTPS in URLs
[skip ci]
2019-08-19 15:49:21 +02:00
Guy Harris
f9c2c905b1 Squelch more narrowing warnings.
Add an ND_BYTES_BETWEEN() macro that computes how many bytes are
present, starting at the second argument and running up to (but not
including) the first argument, and returns that as a u_int (cutting it
to 32 bits on LP64 and LLP64 platforms).

Use that, including using it as a replacement for SMB's PTR_DIFF().
2019-04-18 11:01:55 -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
Antonin Décimo
0b3880c91e Fix small misspellings 2019-01-23 17:28:14 +01: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
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
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
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
53bec533d6 RESP: Use more the ND_TCHECK_1() macro 2018-01-12 21:27:07 +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
c6a0c10533 Use more the ND_TCHECK_1() macro 2018-01-02 16:17:21 +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
29517faf6c More EXTRACT_U_1() replacing direct dereferences. 2017-12-08 17:57:39 -08:00
Francois-Xavier Le Bail
03a2d9c4c1 Use more the EXTRACT_U_1() macro (47/n)
In: if (... *(p) ...) ...
2017-12-05 10:45:44 +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
415160c0c2 Use more ND_TCHECK_n() macros 2017-11-29 21:06:51 +01:00
Guy Harris
8849db237e RESP: Fix overflow check.
At that point, result is a multiple of 10, so it can at most be
2147483640, i.e. (INT_MAX / 10)*10.

If it's less than that, you can add any value between 0 and 9 to it and
it won't overflow.

If it's *equal* to that, you can only add a value between 0 and 7
without overflowing, i.e. the maximum is INT_MAX % 10.

Addresses Coverity CID 1400557.
2017-09-13 12:25:44 +01:00
Guy Harris
a4bcef4c86 RESP: Remove some redundant checks.
Before we break out of the loop, we've already checked for those
conditions.  No need to check for them again.

This fixes Coverity CIDs 1400553 and 1400554.
2017-09-13 12:25:44 +01:00
Guy Harris
db24063b01 CVE-2017-12989/RESP: Make sure resp_get_length() advances the pointer for invalid lengths.
Make sure that it always sends *endp before returning and that, for
invalid lengths where we don't like a character in the length string,
what it sets *endp to is past the character in question, so we don't
run the risk of infinitely looping (or doing something else random) if a
character in the length is invalid.

This fixes an infinite loop discovered by Forcepoint's security
researchers Otto Airamo & Antti Levomäki.

Add a test using the capture file supplied by the reporter(s).
2017-09-13 12:25:44 +01:00
Guy Harris
d3a64d8365 Do better checking of RESP packets.
Don't call strtol() on the contents of a packet; there is *no* guarantee
that it won't run past the end of the buffer, as the buffer isn't a
null-terminated string.  Instead, have our own routine to parse ASCII
numbers (based on the FreeBSD strtol()), which uses ND_TCHECK() and
checks against the on-the-wire length to ensure it doesn't go past the
end of the packet or the end of the captured data.  Have it check for
other errors as well, such as checking for negative lengths that aren't
-1.

Clean up other aspects of the packet parsing.  Have them check the
on-the-wire length as well as the captured length.

Update the results of the resp_3 test.
2017-01-18 09:16:41 +01:00
Francois-Xavier Le Bail
191ba86d88 Remove NETDISSECT_REWORKED macro
See commit 38700c7.
2016-09-01 16:35:30 +02:00
Francois-Xavier Le Bail
b38f324af9 Add a summary comment in all other printers
Moreover:
Remove some redundant comments
Update some summary comments
Update the specification URL for ATA over Ethernet (AoE) protocol
2016-08-15 22:42:38 +02:00
Francois-Xavier Le Bail
978b1f72d9 RESP: Fix Coverity warnings
The warnings were:
Calling "fn_printn" without checking return value (as is done elsewhere
52 out of 56 times)
2016-07-19 14:37:47 +02:00
Guy Harris
549aab2173 Use strtol(), not atoi(), to parse integral values.
strtol()'s error behavior is standardized; atoi()'s isn't.
2016-04-26 03:04:21 -07:00
Andrew Darqui
fc213645d4 Initial support for the REdis Serialization Protocol known as RESP.
This commit adds support for RESP as defined in: http://redis.io/topics/protocol.
It also supports inline commands and pipelining. Due to the popularity of RESP,
numerous services are emerging that use this protocol. You may decode RESP packets
on arbitrary ports using the "-T resp" option.

Example captures can be found in tests/resp_*.

A simple way to test this parser is to start redis-server and then run
redis-cli commands such as "redis-cli set key value".

Traditionally, redis-cli monitor is used to debug redis. Unfortunately,
the "monitor" command can cause significant load on a redis-server in
production. This parser may be used as a non-invasive alternative to
redis-cli monitor.
2016-04-26 11:00:21 +02:00