Commit Graph

134 Commits

Author SHA1 Message Date
Francois-Xavier Le Bail
94a3708f00 Include <config.h> unconditionally
Builds using Autotools or CMake generate config.h, thus remove the
'#ifdef HAVE_CONFIG_H'/'#endif'.

Remove also the 'add_definitions(-DHAVE_CONFIG_H)' in CMakeLists.txt.
2024-03-28 05:34:34 +00:00
Francois-Xavier Le Bail
aa9b00bf94 Multilink Frame Relay: Fix the Timestamp Information Element printing
The specification say nothing about using an Unix timestamp.
Do only an hexa dump.
Add a length test.

FRF.16.1 Section 3.4.4 Timestamp Information Element states:

The maximum length is 14 octets. Format is implementation specific.

Granularity and interpretation of the Timestamp Information Element is
implementation specific.

(https://www.broadband-forum.org/download/FRF.16.1.pdf)
2024-03-05 17:57:47 +01:00
Francois-Xavier Le Bail
113ed15b7e Put "}" at beginning of line with "else" to keep a consistent style
[skip ci]
2023-04-21 14:45:18 +02:00
Guy Harris
df2dc59f6c Frame Relay: make the buffer big enough for the biggest message. 2021-05-25 23:25:41 -07:00
Guy Harris
51bc4bffb8 Frame Relay: have q922_string() handle errors better.
Have it return a string indicating an error, rather than a null string.
2021-05-25 22:26:48 -07:00
Denis Ovsienko
ddbfdb130f FR: Fix a typo in a comment. 2020-09-08 05:10:20 +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
4262b29164 FR: Update the link-layer dissectors to void functions
Moreover:
Remove trailing "_if" from the protocol name.
Add two comments.
2020-08-04 17:25:01 +02:00
Francois-Xavier Le Bail
067280e128 FR: Remove useless "oui.h" include 2020-03-31 14:45:26 +02:00
Francois-Xavier Le Bail
4900c023e3 FRF.16: Add a length check before the bounds check
At the beginning of mfr_print() check the declared length.

Updated from e5ae1fd2c5
in 4.9 branch.
2019-10-28 10:20:55 +01:00
Francois-Xavier Le Bail
ac5baa713c FRF.16: Add a length check
The specification says in a well-formed Magic Number Information Element
the data is exactly 4 bytes long. This gives a more accurate output.

Update the output of a test accordingly.

Partial update from aa3e54f594
in 4.9 branch.
2019-10-19 15:05:46 +02: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
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
e73118bc07 Add more nd_print_trunc() calls
Update the output of some tests accordingly.

Moreover:
Update a ndo_protocol assignment.
2018-05-23 12:07:58 +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
ba857360fc Add some const qualifiers 2018-03-16 10:39:25 +01: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
21aff56b39 FR: Add parentheses when extracting the flags
Should fix Coverity CID 1426919.
2017-12-23 12:20:37 +01:00
Francois-Xavier Le Bail
b04ee9c12e FR: Rework extracting the flags
Moreover:
Rename parse_q922_addr to parse_q922_header
2017-12-17 14:22:14 +01:00
Francois-Xavier Le Bail
e835e6a934 Fix spaces 2017-12-17 13:12:36 +01:00
Francois-Xavier Le Bail
e74cccfe79 FR: Fix extracting the DE flag
Update the output of a test accordingly.
2017-12-17 12:34:13 +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
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
1cfd6cd2ac Use more the EXTRACT_U_1() macro (51/n)
Moreover: Use more the ND_ISPRINT() macro.
2017-12-09 11:46:15 +01:00
Francois-Xavier Le Bail
97de8ca7bd Use more the EXTRACT_U_1() macro (35/n)
In some safeputchar() calls, *(p).
2017-11-30 23:08:07 +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
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
a58370c17f Fix a bound check 2017-11-20 14:18:10 +01:00
Guy Harris
f411a05060 More EXTRACT_8BITS() changes. Use ND_CHECK_nBITS() more as well. 2017-11-19 17:59:51 -08: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
1dcd10acea CVE-2017-12897/ISO CLNS: Use ND_TTEST() for the bounds checks in isoclns_print().
This fixes a buffer over-read discovered by Kamil Frankowicz.

Don't pass the remaining caplen - that's too hard to get right, and we
were getting it wrong in at least one case; just use ND_TTEST().

Add a test using the capture file supplied by the reporter(s).
2017-09-13 12:25:44 +01:00
Denis Ovsienko
26a4aa405a Frame Relay: denote a genuine fall through case
The source code comment explains it should fall through but GCC does not
pick it up, that's what the new macro is for.

./print-fr.c: In function ‘mfr_print’:
./print-fr.c:510:20: warning: this statement may fall through [-Wimplicit-fallthrough=]
                 if (ie_len == sizeof(struct timeval)) {
                    ^
./print-fr.c:521:13: note: here
             case MFR_CTRL_IE_VENDOR_EXT:
             ^~~~
2017-07-22 19:35:06 +01:00
Denis Ovsienko
c39c1d99ac CVE-2017-5482/Q.933: add a missing bounds check
Brian Carpenter had found that regardless of CVE-2016-8575 q933_print()
still could overread the buffer trying to parse a short packet. This
change fixes the problem.
2017-01-18 09:16:41 +01:00
Denis Ovsienko
857ec6e800 pass correct caplen to other functions as well
In ethertype_print(), isoclns_print() and snap_print() adjust the length
arithmetics along the same lines as for ether_print() in the previous
commit. Where done, the current pointer is not greater than snapend so
that the difference (i.e. caplen) is never negative.

This does not fix a reported issue but the problem was very likely to be
there.
2017-01-18 09:16:41 +01:00
Guy Harris
6bc44295cf CVE-2016-7985,7986/Change the way protocols print link-layer addresses.
If a protocol that runs under a link-layer protocol would print the
link-layer addresses for the packet as source and destination addresses
for the packet, don't have it blithely assume those link-layer addresses
are present or are at a particular offset from the beginning of that
protocol's data; Ethertypes, for example, are used by a number of
protocols, not all of which have Ethernet headers and not all of which
have any MAC headers.

Instead, pass the printers for those protocols structures with a pointer
to the address data and a pointer to a routine that prints the address.

Fixes some heap overflows found with American Fuzzy Lop by Hanno Böck.
2017-01-18 09:16:36 +01:00
Guy Harris
273a1a713b Clean up "invalid IE" messages. 2016-09-24 12:06:51 -07:00
Guy Harris
976a6d42dd Fix indentation. 2016-09-24 11:54:32 -07:00
Guy Harris
b32585658d Check for invalid IE lengths.
Also fix a failure to stop printing on error, and rename a routine to
reflect that it's used for codesets 0 and 5.
2016-09-21 18:18:19 -07:00
Guy Harris
547ad06362 More cleanups of Q.933 output. 2016-09-21 02:34:24 -07:00
Guy Harris
262417a225 Clean up printing of Q.933 packets.
Check the packet length and the snapshot length as we parse the packet.
Extract each field as we go.

Support arbitrary call reference lengths, 0 to 15 octets.

Handle single-octet IEs correctly - don't look for a length.

Handle both locking and non-locking shifts correctly.  Don't assume that
the first octet after the message type is a shift and contains a
codeset.  We were doing that, meaning that we tended to think codeset 1
was being used (by misparsing an IE with a code of 0x51 as a shift to
codeset 1) when it wasn't - codeset 0 was being used; correctly handle
codeset 0.
2016-09-21 01:57:55 -07:00