summaryrefslogtreecommitdiff
path: root/extract.h
Commit message (Collapse)AuthorAgeFilesLines
* Remove duplicate wordsFrancois-Xavier Le Bail2020-03-281-1/+1
| | | | [skip ci]
* Add GET_CPY_BYTES() macro and get_cpy_bytes() functionFrancois-Xavier Le Bail2019-09-091-0/+10
| | | | | | | 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.
* Add an include guard in extract.hFrancois-Xavier Le Bail2019-06-291-0/+5
|
* Apply the first step of the new way to fetch data with bounds checkingFrancois-Xavier Le Bail2019-03-261-0/+322
| | | | | | | | | | | 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.
* Updated 802.15.4 codeTero Kivinen2018-11-181-69/+376
|\
| * Don't assume ARM supports unaligned accesses.Guy Harris2018-09-051-4/+10
| | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Fix a typo in the EXTRACT_BE_S_6() macroFrancois-Xavier Le Bail2018-06-151-1/+1
| | | | | | | | S: Signed
| * Add a cast to the EXTRACT_U_1() macroFrancois-Xavier Le Bail2018-05-191-1/+1
| | | | | | | | This change may avoid sign bit extension problem.
| * Fix some host-endian extract routinesFrancois-Xavier Le Bail2018-04-301-3/+3
| | | | | | | | The modified routines are not currently used.
| * Put UNALIGNED_OK at the beginning of the inline declaration.Guy Harris2018-01-291-7/+7
| | | | | | | | | | Stylistic consistency - it's a characteristic of the function, so put it in the list of characteristics, along with "static" and "inline".
| * Don't test for __attribute__ in the configure script.Guy Harris2018-01-211-4/+5
| | | | | | | | | | | | | | | | | | 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.
| * Use nd_ types, add host-endian extract routines, clean up signed vs. unsigned.Guy Harris2018-01-111-0/+50
| | | | | | | | | | 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.
| * Add EXTRACT_ macros/functions for IPv4 addresses, get rid of structure wrappers.Guy Harris2017-12-201-0/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Replace ND_TTEST2()/ND_TCHECK2() macros by macros using pointers (2/n)Francois-Xavier Le Bail2017-12-111-18/+18
| |
| * Clean up signed vs. unsigned.Guy Harris2017-11-231-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Rename EXTRACT_ macrosFrancois-Xavier Le Bail2017-11-221-32/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
| * Rename ND_TCHECK_/ND_TTEST_ macrosFrancois-Xavier Le Bail2017-11-221-18/+18
| | | | | | | | | | | | | | | | 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
| * Add EXTRACT_ macros/functions to get signed integers.Guy Harris2017-11-211-0/+123
| |
| * Remove EXTRACT_LE_8BITS() macro, use EXTRACT_8BITS() macroFrancois-Xavier Le Bail2017-11-181-2/+1
| | | | | | | | This indicates that it's not specifically big-endian or little-endian.
| * Rename EXTRACT_nBITS() macros to EXTRACT_BE_nBITS()Francois-Xavier Le Bail2017-11-181-13/+13
| | | | | | | | | | It indicates clearly that these macros are used to extract big-endian integral values.
| * Check for unaligned memory access support at compile time.Guy Harris2017-10-161-38/+47
| | | | | | | | | | Don't test at configure time; that doesn't work when cross-compiling and may be a pain to do with CMake.
| * CVE-2017-13025/IPv6 mobility: Add a bounds check before fetching dataFrancois-Xavier Le Bail2017-09-131-0/+3
| | | | | | | | | | | | | | | | 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'
| * CVE-2017-13003/Clean up the LMP dissector.Guy Harris2017-09-131-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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).
| * Suppress UBSan warnings from EXTRACT_.Guy Harris2017-08-181-8/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | IEEE 802.15.4 printer which understands frame version 2 frames, and also ↵Tero Kivinen2017-03-261-0/+21
|/ | | | knows how to print some mac commands and IE contents. Also includes the zep printer to decode ZigBee Encapsulation Protocol frames
* CVE-2016-7940/Add a bunch of bounds checks, and fix some printing.Guy Harris2017-01-181-0/+27
| | | | | | | | | | | | | 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..
* Remove unnecessary backslashesFrancois-Xavier Le Bail2016-08-291-2/+2
|
* Use the nd_uintN_t types more.Guy Harris2015-10-071-23/+0
| | | | | | | | | | | | | | 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.
* Introduce data types to use for integral values in packet structures.Guy Harris2015-10-061-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.)
* Fix indentation.Guy Harris2014-10-011-1/+1
|
* Add some more parentheses, Just In Case.Guy Harris2014-10-011-52/+52
| | | | | | | | | | | | | | | | 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.)
* More getting rid of old u_intN_t.Guy Harris2014-04-231-73/+73
|
* Add {40,48,56}-bit big-endian extract macros and use them for DCCP ACKs.Guy Harris2014-02-151-0/+24
| | | | | | | 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.
* Don't use the __attribute__((packed)) on most platforms.Guy Harris2014-02-011-11/+51
| | | | | | | | | | | | 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.
* remove tcpdump's own CVS keywordsDenis Ovsienko2014-01-031-2/+0
| | | | | | 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.
* Convert some versions of EXTRACT_{16,32,64}BITS() to inline functions.Dmitrij Tejblum2013-06-041-14/+39
| | | | It remove the vast majority of strict-aliasing warnings from GCC.
* -add support (TLV parser) for the juniper .pcap extensionshannes2006-01-301-1/+5
| | | | | in lack of pcap-ng we prepend TLV encoded fields before the payload packet on all Juniper proprietary DLTs
* Declare the non-GCCized 64-bit big-endian extraction macro asguy2005-01-151-2/+2
| | | | | EXTRACT_64BITS(), not EXTRACT_LE_64BITS() - thanks to Rick Jones for finding that one.
* Fix the parenthesization in the "alignment required but you canguy2004-09-251-3/+3
| | | | | | | | | 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().
* Don't do the "OR together the result of two "ntohl()"s stuff onguy2004-09-251-9/+24
| | | | | | | platforms that don't support unaligned fetches - just assemble the 64-bit big-endian integer from its constituent bytes. Improve some comments.
* Add an "EXTRACT_64BITS()" macro - using the "EXTRACT_32BITS()" macro, soguy2004-09-241-1/+5
| | | | | we get the fast implementations if we are on a processor that doesn't require alignment.
* cpack uses EXTRACT_LE_64BITS to extract little-endian 64-bit words.dyoung2004-09-231-1/+10
|
* The "__attribute__((packed))" tag on structures causes some files not toguy2002-12-111-3/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | compile with Sun C, as "interface.h" isn't being included before the structures are being declared. Furthermore, in the files that Sun C *can* compile, it doesn't cause Sun C to generate code that's safe with unaligned accesses, as "__attribute__" is defined as a do-nothing macro with compilers that don't support it. Therefore, we get rid of that tag on the structures to which it was added, and instead use "EXTRACT_16BIT()" and "EXTRACT_32BIT()" to fetch 16-bit and 32-bit big-endian quantities from packets. We also fix some other references to multi-byte quantities to get rid of code that tries to do unaligned loads on platforms that don't support them. We also throw in a hack that makes those macros use "__attribute__((packed))" on structures containing only one 16-bit or 32-bit integer to get the compiler to generate unaligned-safe code rather than doing it by hand. (GCC on SPARC produces the same code that doing it by hand does; I don't know if GCC on any other big-endian strict-alignment processor generates better code for that case. On little-endian processors, as "ntohs()" and "ntohl()" might be functions, that might actually produce worse code.) Fix some places to use "%u" rather than "%d" to print unsigned quantities.
* Add a few more GCC warnings on GCC >= 2 for ".devel" builds.guy2002-09-051-16/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From Neil T. Spring: fixes for many of those warnings: addrtoname.c, configure.in: Linux needs netinet/ether.h for ether_ntohost print-*.c: change char *foo = "bar" to const char *foo = "bar" to appease -Wwrite-strings; should affect no run-time behavior. print-*.c: make some variables unsigned. print-bgp.c: plen ('prefix len') is unsigned, no reason to validate by comparing to zero. print-cnfp.c, print-rx.c: use intoa, provided by addrtoname, instead of inet_ntoa. print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to be false, so check for (u_int)-1, which represents failure, explicitly. print-isakmp.c: complete initialization of attrmap objects. print-lwres.c: "if(x); print foo;" seemed much more likely to be intended to be "if(x) { print foo; }". print-smb.c: complete initialization of some structures. In addition, add some fixes for the signed vs. unsigned comparison warnings: extract.h: cast the result of the byte-extraction-and-combining, as, at least for the 16-bit version, C's integral promotions will turn "u_int16_t" into "int" if there are other "int"s nearby. print-*.c: make some more variables unsigned, or add casts to an unsigned type of signed values known not to be negative, or add casts to "int" of unsigned values known to fit in an "int", and make other changes needed to handle the aforementioned variables now being unsigned. print-isakmp.c: clean up the handling of error/status indicators in notify messages. print-ppp.c: get rid of a check that an unsigned quantity is >= 0. print-radius.c: clean up some of the bounds checking. print-smb.c: extract the word count into a "u_int" to avoid the aforementioned problems with C's integral promotions. print-snmp.c: change a check that an unsigned variable is >= 0 to a check that it's != 0. Also, fix some formats to use "%u" rather than "%d" for unsigned quantities.
* Eliminate some unused parameters.fenner2001-09-171-18/+18
| | | | | | | | | | | Use const more. Use EXTRACT_* macros more. Use TCHECK* more. Use tok2str() to replace some home-grown workalikes. smb: - Get rid of private types, use tcpdump-defined types - Rename fdata and fdata1 to smb_fdata and smb_fdata1 to avoid conflict with IRIX library function.
* always use u_intXX_t for protocol format declaration. char/short/int may notitojun2000-10-031-17/+17
| | | | | | come with exact size. while at it, correct signedness of ip/udp header field. nuke most of the use of bitfield. TODO: bitfield in namser.h
* Initial revisionmcr1999-10-071-0/+57