Commit Graph

5887 Commits

Author SHA1 Message Date
Guy Harris
dc59375166 TESTrun.sh is dead; long live TESTrun. 2020-01-24 14:28:34 -08:00
Michael Richardson
df841d9118 translate TESTrun.sh to Perl, still using external routines for complex situations 2020-01-24 17:07:51 -05:00
Michael Richardson
900f4856c1 move test invocation code into subroutine 2020-01-24 16:08:44 -05:00
Guy Harris
77328e886b Fix #ifdef to test for something we set at configuration time. 2020-01-20 11:19:39 -08: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
2cd0a90c24 Use a short timeout, rather than immediate mode, for text output.
That means that we do some buffering of packets.  It also means we don't
depend on the immediate-mode APIs being available.

While we're at it, use the short timeout if we're doing text output in
"line-buffered mode" as well as if we're doing it to a terminal.
2020-01-19 19:34:00 -08:00
Francois-Xavier Le Bail
521ac1db3f LDP: Add some missing bounds checks
Replace calls to ipaddr_string()/ip6addr_string() with calls to
GET_IPADDR_STRING()/GET_IP6ADDR_STRING() macros performing bounds
checking.

Fix a regression in 78a4ee8222.

This fixes a buffer over-read in ldp_tlv_print() discovered by
Jason Xiaole.

Add a test using the capture file supplied by the reporter updated
to keep only the packet showing the buffer over-read.
2020-01-18 19:30:38 +01:00
Guy Harris
840c934e3e Make print_ptp()'s declaration match its definition. 2020-01-05 20:50:19 -08:00
Guy Harris
fba80a0b83 Put the crypto stuff into a common routine.
That makes it easier to 1) change it and 2) use different crypto
libraries for it.
2020-01-05 19:25:00 -08:00
Guy Harris
bd22f1fd9a Clean up ESP and ISAKMP decryption.
At least as I read RFC 5996 section 3.14 and RFC 4303 section 2.4, if
the cipher has a block size of which the ciphertext's size must be a
multiple, the payload must be padded to make that happen, so the
ciphertext length must be a multiple of the block size.  Instead of
allocating a buffer, copying the ciphertext to it, and padding it to the
block size, fail if its size isn't a multiple of the block size.

(Note also that the old padding code added a block's worth of padding to
the end of a ciphertext block that *was* a multiple of the cipher block
size; this might have caused problems.)

Don't use the undocumented EVP_Cipher(); the lack of documentation means
a lack of information about whatever requirements it might impose.  Use
EVP_DecryptUpdate() instead.

Before calling it, use EVP_CIPHER_CTX_set_padding() to say "don't do
your own padding, this block is a multiple of the cipher block size".

Instead of using EVP_CipherInit() or EVP_CipherInit_ex(), use
EVP_DecryptInit() or EVP_DecryptInit_ex().  as we're always doing
decryption and never doing encryption - the extra parameter to
EVP_CipherInit() and EVP_CipherInit_ex() is always 0.

This may address GitHub issue #814.

It may also make it a bit easier to have the code use Common Crypto on
macOS (rather than requiring that OpenSSL be installed - macOS ships
with an OpenSSL shared library for binary compatibility with older
releases, but doesn't ship with the headers, because Apple wants you
using their crypto code) and use Cryptography API: Next Generation on
Windows (Vista/Server 2008 and later) (rather than requiring a Windows
build of OpenSSL).

(Hopefully this will all work with LibreSSL.)
2020-01-05 18:37:52 -08:00
Guy Harris
011ae55410 Fix check of authentication algorithm.
If you split a string by overwriting the separator character with a NUL,
and you want to compare the first part with various values, use a
pointer to the beginning of the string, not to the NUL you just dropped
in.

This is a bug found while testing some cleanups for GitHub issue #814;
it's necessary for the cleanups to work.
2020-01-05 17:49:42 -08:00
Guy Harris
646a1135c4 Use nd_ types - and use GET_U_1() for 1-byte integral values. 2019-12-25 00:55:44 -08:00
Guy Harris
a8c33a5850 The third argument to linkaddr_string is one of the LINKADDR_ enums.
It's *not* just a number like 0.  That *happens* to work, because, even
though LINKADDR_ETHER is currently 0, linkaddr_string() handles link
addresses of type LINKADDR_ETHER with a length other than 6 octets as
just a collection of octets, but we shouldn't *rely* on that.
2019-12-24 17:47:23 -08:00
Guy Harris
35fef089f3
Merge pull request #813 from fenner/rx-truncated
Don't use nd_ipv4 for non-packet data
2019-12-03 17:31:15 -08:00
Bill Fenner
485bd5fa51 Don't use nd_ipv4 for non-packet data
nd_ipv4 was created for an unaligned field access inside of packet data,
so it should not be used for the rx_cache_entry.  Use uint32_t, and use
GET_IPV4_TO_NETWORK_ORDER instead of UNALIGNED_MEMCPY() to get the data
into them.
2019-12-02 04:18:28 -08:00
Francois-Xavier Le Bail
6bbbbc6b65 Fix indentation in "make check" output 2019-11-27 15:44:33 +01:00
Guy Harris
cbd0d78fce Move some code to better show how to handle pcap_activate() failure.
If you call pcap_activate() and it fails, you still have a pcap_t from
pcap_create(), and should close it.

Moving the code after the error() calls doesn't make a difference, as
error() exits, but it may make it clearer to those reading tcpdump.c for
help in figuring out how to use libpcap that you should close the pcap_t
if pcap_activate() fails.

(In the future, there may also be the option of changing some options
and trying again, e.g. changing the user name or password for a remote
capture.)
2019-11-23 19:28:17 -08:00
Partha Ghosh
6f53130273 The ptp (precision time protocol) with UDP as the transport protocol.
- the print routines for ptp different ptp messages
- test completed for sync message, announce message, delay request message,
  delay response message and follow up message.
- integration of the ptp v2 code with the tcpdump code.

Signed-off-by: Partha S. Ghosh <psglinux@gmail.com>
2019-11-22 20:56:21 +01:00
Bill Fenner
74e6075a69 Do not open an interface if not needed for -d 2019-11-13 19:34:07 +01:00
Guy Harris
866358cc52 Clean up rounding up.
Have roundup2() cast the power-of-2 argument to u_int; that way, you
don't have to explicitly define it as an unsigned value in order to
avoid compiler or UBSan complaints about signed integers.

Use it instead of rolling our own rounding-to-a-power-of-2.
2019-11-10 20:51:48 -08:00
Guy Harris
c376b499ae Don't run past the end of an MP_REACH_NLRI attribute.
Keep track of the length of the attribute, and make sure we don't run
past it.
2019-11-10 15:56:19 -08:00
Francois-Xavier Le Bail
37800b45d5 PIM: Fix some length checks
Update the outputs of some tests accordingly.
2019-11-09 15:11:17 +01:00
Francois-Xavier Le Bail
315fe447ea PIM: Fix two length checks 2019-11-09 11:34:17 +01:00
Francois-Xavier Le Bail
da5ac63504 IS-IS: Use %zu to print sizeof values 2019-11-09 11:33:34 +01:00
Francois-Xavier Le Bail
a7a34cc483 IS-IS: Fix some undefined behaviors at runtime
The error were like:
print-isoclns.c:2583:20: runtime error: unsigned integer overflow:
20 - 27 cannot be represented in type 'unsigned int'

print-isoclns.c:2525:20: runtime error: unsigned integer overflow:
0 - 20 cannot be represented in type 'unsigned int'

Update the output of two tests accordingly.
2019-11-08 21:41:47 +01:00
Francois-Xavier Le Bail
0ec7203f8c Cleaning spaces
[skip ci]
2019-11-07 09:24:09 +01:00
Francois-Xavier Le Bail
e1bd3ba135 timed: Add three test capture files
These capture files triggered a buffer over-read fixed by
6f2cd8cee6.

Two pcap files were updated to pass the sanity checks.

Update the outputs of the tests accordingly.
2019-11-05 14:35:02 +01:00
Francois-Xavier Le Bail
9183b5cd38 SMB: Add two test capture files
These capture files triggered a buffer over-read or a segmentation fault
with the 4.9.2 release fixed in the 4.9.3 release.

These errors were fixed in master branch by commit
daa343d8e2.

Update the outputs of the tests accordingly.

Partial update from b8f025d17f
in 4.9 branch.
2019-11-04 19:58:26 +01:00
Denis Ovsienko
c9e5ac541b libdnet has bugs, do not use it.
The only function tcpdump used in libdnet was dnet_htoa(), which tries
to translate a binary DECnet address to a nodename through a lookup in
/etc/decnet.conf. The translation is slow and has a bug, so stop using
the function and remove the dependency on libdnet.

This makes tcpdump always print DECnet addresses in numeric format, if
anybody needs the translation back they are welcome to fix libdnet or
(more realistically) add an implementation of dnet_htoa() to the tcpdump
source code and use it.

(This is a forward-port of commit 9a6eb27 from tcpdump-4.9 to master.
Sadly, together with libdnet this change removes the fine work that Guy
had done in the master branch in commits ebf3f19 and 4ef8d63 to put
libdnet usage right whilst my original "do not use libdnet" commit was
aging in the pipeline.)
2019-11-03 23:46:28 +00:00
Francois-Xavier Le Bail
eabcd87c1d Update some test capture files
These changes avoid some pcap_loop() errors messages like:
"tcpdump: pcap_loop: invalid packet capture length X, bigger than
snaplen of Y"
or
"tcpdump: pcap_loop: truncated dump file; tried to read X header
bytes, only got Y"

Update the output of the tests accordingly (no more "EXIT CODE" line).

Remove the no more useful .out.stderr files.
2019-11-02 21:49:18 +01:00
Francois-Xavier Le Bail
18d7f66224 Update some test capture files
These changes avoid some pcap_loop() errors messages like:
"tcpdump: pcap_loop: invalid packet capture length X, bigger than
snaplen of Y"
or
"tcpdump: pcap_loop: truncated dump file; tried to read X captured
bytes, only got Y"

The outputs of the tests are unchanged.

Remove the no more useful -c options in the test configurations.
2019-11-02 21:18:22 +01:00
Francois-Xavier Le Bail
be5066b9b4 Remove useless -c options in some test configurations 2019-11-02 19:30:23 +01:00
Francois-Xavier Le Bail
c2175fa061 Remove some .out.stderr files
There is no error.
2019-11-02 18:46:40 +01:00
Francois-Xavier Le Bail
f8746883cb SMB: Move smb_data_print() declaration in smb.h
smb_data_print() is only called in print-smb.c and smbutil.c.
2019-11-01 10:38:21 +01:00
Francois-Xavier Le Bail
c5a34f01b4 sFlow: Add a test capture file
This capture file triggered a buffer over-read with the 4.9.2 release
fixed in the 4.9.3 release.

The problem was fixed in master branch by commit
09822d484b.

Update the output of the test accordingly.

Update from b35eb4c163
in 4.9 branch.
2019-10-30 10:47:07 +01:00
Guy Harris
42ddfda12d Require CMake 3.12 or later on Windows.
We require it for policy CMP0074, so the user can tell CMake where the
Npcap or WinPcap SDK is hiding with -DPCAP_ROOT=.
2019-10-29 20:09:14 -07:00
Guy Harris
c05087101a Use PCAP_ROOT to tell CMake where to find Npcap or WinPcap. 2019-10-29 18:45:43 -07:00
Francois-Xavier Le Bail
c58f88896c SMB: Add two test capture files
These are tests for print-smb.c:print_trans().

These capture files triggered a buffer over-read fixed by
50f375f9f1.

The pcap files were updated to avoid pcap_loop() error messages.

Update the output of the tests accordingly.

Update from 4bfd71eee4
in 4.9 branch.
2019-10-29 12:42:12 +01:00
Guy Harris
a92e68613c Fix a compiler warning.
We need to ensure that buf2 is set even if we have too many nested "*"s
in an SMB format string.

Add comments to further explain that code.

Cherry picked from 9e49bfe4b9
in 4.9 branch.
2019-10-29 09:36:08 +01:00
Denis Ovsienko
42857bd6a9 SMB: prevent stack exhaustion
Enforce a limit on how many times smb_fdata() can recurse.

This change fixes CVE-2018-16452.

This fixes a stack exhaustion discovered by Include Security working
under the Mozilla SOS program in 2018 by means of code audit.

Cherry picked from 24182d959f
in 4.9 branch.
2019-10-29 09:29:19 +01:00
Denis Ovsienko
756d0a1356 BGP: prevent stack exhaustion
Enforce a limit on how many times bgp_attr_print() can recurse.

This change fixes CVE-2018-16300.

This fixes a stack exhaustion discovered by Include Security working
under the Mozilla SOS program in 2018 by means of code audit.

Cherry picked from af2cf04a93
in 4.9 branch.
2019-10-28 20:10:56 +01:00
Denis Ovsienko
8d32220a44 Babel: Add a missing length check.
In babel_print_v2() check that the Babel packet body length does not
exceed the outer UDP packet payload. This helps to detect some invalid
packets earlier but does not fix a known vulnerability.

Update the output of a test accordingly.

Cherry picked from 651020754a
in 4.9 branch.
2019-10-28 19:09:38 +01:00
Francois-Xavier Le Bail
6d20b784a3 Babel: Add a test capture file
This capture file triggered a buffer over-read with the 4.9.2 release
fixed in the 4.9.3 release.

With the new GET_ macros, the problem no longer exists.
Thus no fix needed.

The pcap file was updated to pass the sanity checks and to avoid
pcap_loop() error messages.

Moreover:
Fix an existing length check.

Update the output of the test accordingly.

Partial update from 12f66f69f7
in 4.9 branch.
2019-10-28 18:01:22 +01: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
Denis Ovsienko
7ade781cf7 Fix -V to fail invalid input safely
This change fixes CVE-2018-14879.

get_next_file() did not check the return value of strlen() and
underflowed an array index if the line read by fgets() from the file
started with \0. This caused an out-of-bounds read and could cause a
write. Add the missing check.

This vulnerability was discovered by Brian Carpenter & Geeknik Labs.

Cherry picked from 9ba9138195
in 4.9 branch.
2019-10-27 21:00:52 +01:00
Pedro Monreal
b374c49a58 PGM: Fix order when printing PGM_OPT_REDIRECT_FIXED_LEN and opt_len
in pgm_print().
2019-10-24 21:57:54 +02:00
Francois-Xavier Le Bail
4f604725d3 OpenFlow: Add a test capture file
This capture file triggered a buffer over-read with the 4.9.2 release
and was fixed in the 4.9.3 release.

The problem was fixed in master branch by commit
ad69daa2e4.

Update the output of the test accordingly.

Partial update from 1ccaff3764
in 4.9 branch.
2019-10-24 15:50:29 +00:00
Francois-Xavier Le Bail
4ad4b6ee7d DCCP: Add a test capture file
This capture file triggered a buffer over-read with the 4.9.2 release
and was fixed in the 4.9.3 release.

The problem was fixed in master branch by commit
6df4852ec3.

The pcap file was updated to avoid pcap_loop() error messages.

Update the output of the test accordingly.

Partial update from 211124b972
in 4.9 branch.
2019-10-24 17:39:09 +02:00
Francois-Xavier Le Bail
9f09ec3ee6 IEEE 802.11: Add a test capture file
This capture file triggered a buffer over-read with the 4.9.2 release
fixed in the 4.9.3 release.

With a previous fix (3f1c4af001),
the problem no longer exists.

The pcap file was updated to pass the sanity checks and to avoid
pcap_loop() error messages.

Update the output of the test accordingly.

Partial update from 4846b3c5d0
in 4.9 branch.
2019-10-24 14:37:36 +00:00
Francois-Xavier Le Bail
30786e36e2 HNCP: Add a test capture file
This capture file triggered a buffer over-read with the 4.9.2 release
fixed in the 4.9.3 release.

With a previous update (511915bef7),
the problem no longer exists.
Thus no fix needed.

The pcap file was renamed from pcapng to pcap because it is.

Update the output of the test accordingly.

Partial update from 83a412a527
in 4.9 branch.
2019-10-24 13:13:00 +00:00