Commit Graph

224 Commits

Author SHA1 Message Date
Guy Harris
0dad1934af Have ip{6}addr_string take a u_char * as the second argument.
Fix warnings that introduces.
2018-01-31 00:43:45 -08: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
b89e946e5e Make the cases in bgp_capabilities_print() more similar to each other. 2018-01-25 22:38:34 -08:00
Guy Harris
93f3561210 Add length checks.
Also add some bounds checks whose absence was noted while looking for
length checks that needed to be added, and clean up one output issue
that showed up if an attribute in ATTR_SET had no flags.

Update test output.
2018-01-25 22:26:26 -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
Guy Harris
57ad83491a Don't treat going past the end of the buffer in check_add_path() as an error.
It's just a heuristic test to try to guess whether the NLRI information
has path IDs or not.  If we run past the end of the packet data, just
stop processing before we try to fetch data past the end, don't return
an error.

This keeps us from showing truncation in non-truncated packets.

Update tests to reflect that change.
2017-12-31 01:49:47 -08:00
Francois-Xavier Le Bail
b32ecce30a BGP: Add two missing bounds checks
Update the outputs of three tests accordingly.
2017-12-26 22:15:16 +01:00
Guy Harris
4d55e68443 Fix some things.
decode_labeled_vpn_l2() should return the full length of the item,
including the header; fix it to do so.

Fix calculation of length-in-bytes from length-in-bits.

Add additional length checks.

Do checks of unsigned values against zero as "not equal to zero" rather
than "greater than zero" (they should compile to the same code as, for
unsigned values. they mean the same thing, but that makes it a bit
clearer than it's not as if we're testing for negative values).
2017-12-24 13:43:10 -08:00
Guy Harris
ed466dcc5a Clean up signed vs. unsigned, add initializations to squelch complaints.
Some compilers don't figure out that path_id is always set if add_path*
is "true".  Explicitly initialize it to eliminate complaints from those
compilers.
2017-12-24 13:42:42 -08:00
Guy Harris
57efe20b35 Get rid of an unused variable. 2017-12-18 12:29:08 -08:00
Guy Harris
ed4e3d85a3 More cleanups.
Add the current BGP RFC as a comment.

Use unsigned types where appropriate.

Use size_t where appropriate.

Further whitespace cleanups.
2017-12-16 10:50:00 -08:00
Francois-Xavier Le Bail
6d65e3df34 Use more the EXTRACT_U_1() macro (56/n) 2017-12-16 15:01:02 +01:00
Guy Harris
eb58492d87 More whitespace cleanup. 2017-12-16 00:05:49 -08:00
Guy Harris
1a859e9f5c Re-fix indentation. 2017-12-15 22:51:45 -08:00
Guy Harris
27cc76fd53 Fix build. 2017-12-15 22:37:49 -08:00
Guy Harris
6ec714988c
Merge branch 'master' into master 2017-12-15 22:34:42 -08:00
Guy Harris
6ceeae50d8 Temporarily undo whitespace cleanups to help a pull request.
Hopefully this will reduce the number of conflicts.
2017-12-15 22:32:02 -08:00
Guy Harris
ae1a0ebcd6 Clean up white space.
Consistently use 4-space, no-tab indentation.
2017-12-15 22:29:24 -08:00
Guy Harris
c9ed5865f3 Redo BGP dissection a bit.
Don't copy structures out of the packet, access them in-place using the
EXTRACT_ macros as appropriate, as we already did for some packet types.
Declare the structures using nd_ types.

Rename bgp_header_print() to bgp_pdu_print(), because, after dissecting
and printing stuff from the header, it calls routines to dissect the
body.
2017-12-15 16:04:26 -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
6bb65331a5 Use more the EXTRACT_U_1() macro (53/n)
Assignment, p[n], (more)
2017-12-10 11:40:35 +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
451ac4c753 Use more the ND_TCHECK_1() macro 2017-12-04 21:00:57 +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
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
e83dfd9b16 Simplify some expressions
This will also help some future scripted code updates.
2017-12-02 20:52:22 +01:00
Francois-Xavier Le Bail
320f3db18f Use more the EXTRACT_U_1() macro (34/n)
In some snprintf() calls.
2017-11-29 10:31:10 +01:00
Francois-Xavier Le Bail
2858e729ed Use more the EXTRACT_U_1() macro (29/n)
In ND_PRINT() macro call(s) (step 8).

*(p + e)
2017-11-26 21:33:24 +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
39c8c55aa9 Use more ND_TCHECK_n()/ND_TTEST_n() macros 2017-11-24 22:48:55 +01:00
Guy Harris
862b1d31ed Get rid of unnecessary casts; 2017-11-23 13:13:13 -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
93bee24026 Use pointer expressions like in most similar cases 2017-11-20 22:58:59 +01:00
Francois-Xavier Le Bail
716e07e060 Use more the EXTRACT_8BITS() macro to fetch a one-byte value (12/n)
In ND_PRINT() macro calls.
2017-11-20 09:40:00 +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
ea759b171c Use more the EXTRACT_8BITS() macro to fetch a one-byte value (2/n)
In tok2str() calls.
2017-11-19 13:26:02 +01: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
David Cronin
c8544a787c tok2str-oobr-1: fixed issue where test reading a withdrawn routes of length 1 byte and then would truncate the content as 1 byte is not enough room for the prefix. Now the code will skip the withdrawn routes entirely if it is less then two bytes, which is the minimum needed. The code will no longer print 'Withdrawn Routes: 1 bytes', I feel this no longer makes sense.
bgp_mvpn_6_and_7 && bgp_pmsi_tunnel-oobr && bgp_vpn_rt-oobr: All contained illegal prefix lengths in the withdrawn routes section, ie > than 32 for ipv4, so I modified the .pcap files to have legal prefixs so that the BGP wasn't truncated and updated the withdrawn routes in the test.out
2017-11-12 13:01:56 +00:00
David Cronin
f909c77aa0 fixed warning of mixed declarations and code 2017-11-11 18:35:18 +00:00
David Cronin
ced1cac732 Added ability to decode bgp add-path for updated and withdrawn routes for ipv4 and ipv6. Since there is no flag to signal that a message contains add-path content, a heuristic approach is taken where we assume an add-path format if an add-path message is sensible and that standard bgp is not. In this way we will only display as add-path if displaying as regular bgp was in some way incorrect anyway. Also modified bgp_update_print to correctly decode withdrawn routes as IPv4 as IPv6 routes are always in MP_UNREACH_NLRI. 2017-11-11 17:03:12 +00:00
Denis Ovsienko
66c434bac2 BGP: Fix a typo. 2017-09-13 14:03:58 +01:00
Denis Ovsienko
bd4e697ebd CVE-2017-13053/BGP: fix VPN route target bounds checks
decode_rt_routing_info() didn't check bounds before fetching 4 octets of
the origin AS field and could over-read the input buffer, put it right.

It also fetched the varying number of octets of the route target field
from 4 octets lower than the correct offset, put it right.

It also used the same temporary buffer explicitly through as_printf()
and implicitly through bgp_vpn_rd_print() so the end result of snprintf()
was not what was originally intended.

This fixes a buffer over-read discovered by Bhargava Shastry,
SecT/TU Berlin.

Add a test using the capture file supplied by the reporter(s).
2017-09-13 12:25:44 +01:00
Denis Ovsienko
d515b4b4a3 CVE-2017-13043/BGP: fix decoding of MVPN route types 6 and 7
RFC 6514 Section 4.6 defines the structure for Shared Tree Join (6) and
Source Tree Join (7) multicast VPN route types. decode_multicast_vpn()
didn't implement the Source AS field of that structure properly, adjust
the offsets to put it right.

This fixes a buffer over-read discovered by Bhargava Shastry,
SecT/TU Berlin.

Add a test using the capture file supplied by the reporter(s).
2017-09-13 12:25:44 +01:00
Denis Ovsienko
d10a0f980f CVE-2017-13046/BGP: fix an existing bounds check for PMSI Tunnel
This fixes a buffer over-read discovered by Bhargava Shastry,
SecT/TU Berlin.

Add a test using the capture file supplied by the reporter(s).
2017-09-13 12:25:44 +01:00
Francois-Xavier Le Bail
78ba87d130 BGP: Fix a test invalid on a 32 bits system
The 'len - (tptr - pptr)' expression type is 'unsigned int' on a 32 bits
system.
Thus the conversion changes negative values to positive ones and the > 0
test is invalid.
Update the expression to compare two pointers.
2017-09-13 12:25:44 +01:00