Commit Graph

57 Commits

Author SHA1 Message Date
Denis Ovsienko
b779eda489 Include diag-control.h only where necessary.
Neither addrtoname.c nor extract.h nor netdissect.h nor print-sll.c
require the header anymore, so do not include it there.  Add a missing
conditional include to netdissect.c.
2024-04-02 11:36:13 +01:00
Guy Harris
0a7ba51676 Add macros to fetch big-endian 4-byte and 8-byte IEEE floating point.
Bury the union-of-float-and-unsigned-int hack inside inline functions
and define macros to call them, rather than doing the same trick in
several dissectors.
2024-02-25 15:39:49 -08:00
Josh Soref
38050da48e Fix spelling
* account
* address
* adjacency
* alignment
* anymore
* ascii
* assumption
* blithely
* canonical
* compound
* consecutive
* control
* diagnostics
* disassociation
* fairly
* fallthrough
* greatest
* identification
* multihop
* multiplexed
* nonexistent
* notifiable
* notwithstanding
* number
* polynomial
* preexisting
* proprietary
* quenches
* reassociation
* redefinition
* refresh
* solicitation
* specifying
* support
* the
* unacceptable

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-08-20 07:19:40 +00:00
Francois-Xavier Le Bail
7d2bc7fcb5 Fix some typos
[skip ci]
2022-07-04 14:03:15 +02:00
Guy Harris
518e1bf60b Move nd_trunc_longjmp() to netdissect.h with the other nd_ functions.
It's not particularly tied to the data-extraction functions; this makes
it available elsewhere.
2022-03-28 12:44:50 -07:00
Denis Ovsienko
604cd4aa60 Use __builtin_unreachable(). [skip ci]
Same as in libpcap.
2021-08-15 11:12:00 +01:00
Denis Ovsienko
b7401ffd86 Squelch a noreturn warning on AIX. [skip ci]
GCC 8.3.0 on AIX 7.1 produced a warning for every file that has a call
to nd_trunc_longjmp():

In file included from ./cpack.c:39:
./extract.h: In function 'nd_trunc_longjmp':
./extract.h:586:1: warning: 'noreturn' function does return

As far as longjmp(3) man page and <setjmp.h> header go, longjmp() is as
noreturn in AIX as everywhere else, but not in a way that GCC can tell.

Disabling -Wsuggest-attribute=noreturn and -Wmissing-noreturn had no
apparent effect, so instead of using diag-control.h add an infinite loop
on AIX to squelch the warning.
2021-07-26 12:01:00 +01:00
Denis Ovsienko
74e3481289 Rename nd_trunc() to nd_trunc_longjmp(). 2020-09-27 21:48:16 +01:00
Francois-Xavier Le Bail
a2a16f6b4c Use a switch to manage the setjmp() return values
Also rename 'ndo_truncated' to 'ndo_early_end'.

The current case (truncated packet) uses ND_TRUNCATED value.

Prepare to add other cases when the current packet cannot be processed
any more ('Invalid' cases, etc.).
2020-09-18 13:27:48 +02:00
Denis Ovsienko
729a57f75a Introduce and use nd_trunc(). [skip ci]
This new function is a part of item 2 of the longjmp() conversion plan
Francois-Xavier proposed on tcpdump-workers. As a noreturn function, it
can fit uniformly at the end of any decoder function, regardless if void
or not, for example:

const u_char *
something_print (netdissect_options *ndo, const u_char *cp, u_int len)
{
  /* (some normal decoding) */
  ND_TCHECK_2(cp);
  /* (some more normal decoding) */
  return cp + len;

trunc:
  nd_trunc(ndo);
  /* The compiler does not warn about a missing return. */
}
2020-09-17 15:01:25 +01:00
Francois-Xavier Le Bail
9c615ba434 Remove duplicate words
[skip ci]
2020-03-28 16:23:20 +01:00
Francois-Xavier Le Bail
aeb4d52613 Add GET_CPY_BYTES() macro and get_cpy_bytes() function
With setjmp/longjmp logic to call the UNALIGNED_MEMCPY() macro
after bounds checking.

The macro must be used with a packet buffer pointer as second parameter.
2019-09-09 19:59:21 +02:00
Francois-Xavier Le Bail
81d7cd0139 Add an include guard in extract.h 2019-06-29 21:22:19 +02:00
Francois-Xavier Le Bail
176e182416 Apply the first step of the new way to fetch data with bounds checking
Add GET_{BE|HE|LE}_, GET_U_1, GET_S_1, GET_IPV4_TO_HOST_ORDER,
GET_IPV4_TO_NETWORK_ORDER macros and
get_{be|he|le}_, get_u_1, get_s_1, get_ipv4_to_host_order,
get_ipv4_to_network_order inline functions,
with setjmp/longjmp logic to do better and easier data fetch with
bounds checking.

Based on Guy Harris's idea and code.
2019-03-26 21:06:06 +01:00
Tero Kivinen
32e24ead3b Updated 802.15.4 code 2018-11-18 04:35:46 +07:00
Guy Harris
e0a88590e7 Don't assume ARM supports unaligned accesses.
Prior to ARMv6, it didn't support it.  ARMv6 supports it, if the "don't
act like ARMv5" bit isn't set in the system control register, but has
another bit in the system control register to cause unaligned accesses
to fault rather than succeed.  ARMv7 and later don't have "act like
ARMv5" mode, but still has the "fault on unaligned access" bit.

At least some OSes might set the "fault on unaligned access" bit; if
your OS *doesn't* set it, feel free to modify the #if to check for your
OS and for ARM.
2018-09-05 20:26:39 -07:00
Francois-Xavier Le Bail
52f7baee0c Fix a typo in the EXTRACT_BE_S_6() macro
S: Signed
2018-06-15 22:21:28 +02:00
Francois-Xavier Le Bail
3efcefafd8 Add a cast to the EXTRACT_U_1() macro
This change may avoid sign bit extension problem.
2018-05-19 20:43:35 +02:00
Francois-Xavier Le Bail
378568f2a6 Fix some host-endian extract routines
The modified routines are not currently used.
2018-04-30 17:07:36 +02:00
Guy Harris
e68daf3cd9 Put UNALIGNED_OK at the beginning of the inline declaration.
Stylistic consistency - it's a characteristic of the function, so put it
in the list of characteristics, along with "static" and "inline".
2018-01-29 11:58:31 -08:00
Guy Harris
45fc519a2a Don't test for __attribute__ in the configure script.
Instead, use compiler test macros to check whether *particular*
attributes are supported, and set various #defines appropriately, in
header files.

Rename the UNALIGNED structure attribute to ND_UNALIGNED, and ask
whether we still need it.
2018-01-21 17:57:20 -08:00
Guy Harris
fe225c5518 Use nd_ types, add host-endian extract routines, clean up signed vs. unsigned.
We now define the structures for Linux USB headers in print-usb.c, so it
doesn't need to include <pcap/usb.h>; don't check for it.
2018-01-11 11:10:21 -08:00
Guy Harris
b347189ca6 Add EXTRACT_ macros/functions for IPv4 addresses, get rid of structure wrappers.
Add EXTRACT_IPV4_TO_HOST_ORDER() and EXTRACT_IPV4_TO_NETWORK_ORDER();
the former extracts a possibly-unaligned IPv4 address, in network byte
order, returning a uint32_t in host byte order, and the latter extracts
a possibly-unaligned IPv4 address, in network byte order, returning a
uint32_t in *network* byte order.  Some APIs take an address in network
byte order, and some operations are more easily done in host byte order,
so both are useful.

Remove the structure wrappers around nd_ipv4 and nd_ipv6; that makes it
easier to pass variables of those types to functions/macros that take a
byte pointer as an argument (because they might be used either with
pointers to structure members or raw buffer pointers), and the structure
probably wouldn't do much to prevent people from using EXTRACT_BE_U_4()
when they really want to extract the value in *network* byte order;
using the above EXTRACT_IPV4_ calls should do more to encourage that.
2017-12-20 01:07:48 -08:00
Francois-Xavier Le Bail
e2f0616cd0 Replace ND_TTEST2()/ND_TCHECK2() macros by macros using pointers (2/n) 2017-12-11 22:21:33 +01:00
Guy Harris
c45bfbe0ab Clean up signed vs. unsigned.
Have separate cpack_ routines for signed and unsigned numbers, with the
signed ones using _S_ extract macros.  That way, we can do more type
checking.

Add EXTRACT_LE_S_ macros.

Use signed variables for IEEE80211_RADIOTAP_TX_ATTENUATION and
IEEE80211_RADIOTAP_DB_TX_ATTENUATION, rather than using unsigned
variables that we cast to int.

Also, use EXTRACT_U_1() in cpack_uint8.
2017-11-23 11:19:38 -08: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
Guy Harris
eb3e918e0a Add EXTRACT_ macros/functions to get signed integers. 2017-11-21 00:47:12 -08:00
Francois-Xavier Le Bail
5287bffd3f Remove EXTRACT_LE_8BITS() macro, use EXTRACT_8BITS() macro
This indicates that it's not specifically big-endian or little-endian.
2017-11-18 15:00:31 +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
Guy Harris
2b9bfa05b6 Check for unaligned memory access support at compile time.
Don't test at configure time; that doesn't work when cross-compiling and
may be a pain to do with CMake.
2017-10-16 01:39:10 -07:00
Francois-Xavier Le Bail
5338aac7b8 CVE-2017-13025/IPv6 mobility: Add a bounds check before fetching data
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), modified
so the capture file won't cause 'tcpdump: pcap_loop: truncated dump file'
2017-09-13 12:25:44 +01:00
Guy Harris
a25211918f CVE-2017-13003/Clean up the LMP dissector.
Do a lot more bounds and length checks.

Add a EXTRACT_8BITS() macro, for completeness, and so as not to confuse
people into thinking that, to fetch a 1-byte value from a packet, they
need to use EXTRACT_16BITS() to fetch a 2-byte value and then use
shifting and masking to extract the desired byte.  Use that rather than
using EXTRACT_16BITS() to fetch a 2-byte value and then shifting and
masking to extract the desired byte.

Don't treat IPv4 addresses and unnumbered interface IDs the same; the
first should be printed as an IPv4 address but the latter should just be
printed as numbers.  Handle IPv6 addresses in more object types while
we're at it.

This fixes a buffer over-read 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
141c1c6f49 Suppress UBSan warnings from EXTRACT_.
Yes, the behavior of an access with an improperly-aligned pointer is
undefined according to the C standard, but if we're doing that in an
EXTRACT_ function/macro, we're doing it because we know it's safe and
because it's faster than picking the bytes out one by one and assembling
them, so suppress those warnings.

Pull over libpcap's funcattrs.h and use it to do a bunch of checks for
various function attributes; that defines __has_attribute(), so we can
use it to check for the "suppress sanitizer warnings" attribute.

While we're at it, use other things it defines to specify "this function
never returns", "this function is printf-like", and "this function
argument is a printf-style format argument", rather than using various
configure-script checks.  That should let us declare some function
attributes with Microsoft Visual Studio's compilers.
2017-08-18 20:11:43 -07:00
Tero Kivinen
13ebc79dfc IEEE 802.15.4 printer which understands frame version 2 frames, and also knows how to print some mac commands and IE contents. Also includes the zep printer to decode ZigBee Encapsulation Protocol frames 2017-03-26 04:48:28 +03:00
Guy Harris
968776fbf5 CVE-2016-7940/Add a bunch of bounds checks, and fix some printing.
The bounds checks fix some heap overflows found with American Fuzzy Lop
by Hanno Böck.

Add some ND_TTEST_/ND_TCHECK_ macros to extract.h to simplify writing
bounds checks for code that uses the other macros in that file.

Fix the printing of the SPB BPDU agreement digest - I don't think the
intent was to print the value of the first 4 bytes, that value + 4, that
value + 8, etc., I suspect it was to print the first 4 bytes, the next 4
bytes, etc..
2017-01-18 09:16:37 +01:00
Francois-Xavier Le Bail
53f4f63a09 Remove unnecessary backslashes 2016-08-29 20:02:29 +02:00
Guy Harris
bfe9582ec6 Use the nd_uintN_t types more.
Define them in netdissect.h.

Use them in ip.h, and *don't* mark the structures as UNALIGNED; that
should no longer be necessary.

Add a new nd_ipv4 type to use as an IPv4 address; it represents the 4
bytes of IPv4 address as an array of unsigned chars, so that its natural
alignment is only on a byte boundary.

Those changes found some places where we weren't using
UNALIGNED_MEMCPY() to extract IPv4 addresses from packets; use it.
2015-10-07 00:14:20 -07:00
Guy Harris
1376682ba5 Introduce data types to use for integral values in packet structures.
They are defined as arrays of bytes, so

	1) no padding is inserted before them to put them on natural
	   boundaries, so they can be used if the values *aren't* so
	   aligned;

	2) you have to use EXTRACT_ macros with them - which you should
	   be doing *anyway*, to avoid explicitly or implicitly making
	   assumptions about byte order or alignment safety on the
	   platform for which your code is being built (it'd better work
	   when built for little-endian x86 or for big-endian *and*
	   strict-alignment-requiring SPARC).

Use them in the LISP (no, not the programming language!) dissector;
UNALIGNED means "this structure is not guaranteed to be aligned as a
whole, so don't generate code that assumes it is", not "this structure's
individual members shouldn't have padding to put them on natural
boundaries", so it's not sufficient to do that.  (Using these types
*might* suffice to ensure that code that assumes alignment not be
generated, but never underestimate SPARC compilers' eagerness to use
single load and store instructions to fetch big-endian 16-bit, 32-bit,
and 64-bit values from packets that really aren't guaranteed to be
aligned.)
2015-10-06 09:41:01 -07:00
Guy Harris
6209302df6 Fix indentation. 2014-10-01 17:55:59 -07:00
Guy Harris
214eb814ee Add some more parentheses, Just In Case.
I'm not sure whether

	Performing a byte swapping operation on "p" implies that it came
	from an external source, and is therefore tainted.

from Coverity means that it thinks we're byte-swapping the pointer
*itself*, or that we're byte-swapping what it points to, but, just in
case it's the former, let's try throwing some more parentheses in.

(If it's the latter, well, yes, it's packet data, so it comes from an
external source, but Coverity didn't seem to point out any place where
we were using the data it points to without checking its value in cases
where we have to.)
2014-10-01 13:12:13 -07:00
Guy Harris
dbddfda2c8 More getting rid of old u_intN_t. 2014-04-23 00:45:13 -07:00
Guy Harris
f5e2e1a4a5 Add {40,48,56}-bit big-endian extract macros and use them for DCCP ACKs.
Add macros to, given an octet pointer, extract 40-bit, 48-bit, and
56-bit big-endian numbers from the location pointed to by that pointer,
and use them when extracting ACK numbers from DCCP packets.  This fixes
problems on big-endian(!) machines.
2014-02-15 20:37:28 -08:00
Guy Harris
78f0dde7c9 Don't use the __attribute__((packed)) on most platforms.
It won't necessarily work with non-GCC-compatible compilers, so use it
only on GCC-compatible compilers.

Even with some GCC-compatible compilers (such as, err, umm, GCC), it
doesn't do the right thing on some platforms, e.g. 64-bit SPARC, where
the compiler generates code that assumes alignment even when using it.
The only platforms I know of where an unaligned big-endian load can be
done better than by loading bytes and shifting-and-ORing them together
are MIPS and possibly Alpha, so only do it there.
2014-02-01 14:02:17 -08:00
Denis Ovsienko
fe3253b9b8 remove tcpdump's own CVS keywords
Remove lots of $Header's and a few $Id's that all belong to the former
CVS repository of tcpdump itself. These keywords have been frozen since
the migration to git in late 2008.
2014-01-03 00:59:08 +04:00
Dmitrij Tejblum
772d6fbcf5 Convert some versions of EXTRACT_{16,32,64}BITS() to inline functions.
It remove the vast majority of strict-aliasing warnings from GCC.
2013-06-04 14:49:52 +04:00
hannes
b26f4c74ba -add support (TLV parser) for the juniper .pcap extensions
in lack of pcap-ng we prepend TLV encoded fields
  before the payload packet on all Juniper proprietary DLTs
2006-01-30 16:20:06 +00:00
guy
b3fff6c41e Declare the non-GCCized 64-bit big-endian extraction macro as
EXTRACT_64BITS(), not EXTRACT_LE_64BITS() - thanks to Rick Jones for
finding that one.
2005-01-15 02:06:50 +00:00
guy
3b97eb047b Fix the parenthesization in the "alignment required but you can
convince GCC to generate alignment-safe loads by using
__attribute((packed))" version of EXTRACT_64BITS().

Fix one of the byte offsets in the "alignment required and we don't know
how to trick the compiler into generating alignment-safe loads" version
of EXTRACT_64BITS().
2004-09-25 07:41:44 +00:00
guy
923f10c8b8 Don't do the "OR together the result of two "ntohl()"s stuff on
platforms that don't support unaligned fetches - just assemble the
64-bit big-endian integer from its constituent bytes.

Improve some comments.
2004-09-25 06:48:14 +00:00