Skip to content

Commit

Permalink
Merge branch '4.3' into PR_#397_multi_pcap_sleep_calc
Browse files Browse the repository at this point in the history
* 4.3:
  #409 check packet length in packet2tree functions (#440)
  #408 check packet length in get_l2len
  #410 check packet length in get_l2protocol
  #432 restore config.h.in
  #407 #408 #409 #410 create branch for downstream PR
  Bug #432 Attempt to use local libopts to fix Travis CI (#433)
  fix heap-buffer-overflow in flow_decode()
  Bug #430 - properly parse libpcap version numbers
  fix some small gcc 7 warnings (#403)
  fix -Wmemset-elt-size warning found by gcc-7
  fix -Wbool-operation warnings found by gcc-7

Conflicts:
	configure.ac
	docs/CHANGELOG
  • Loading branch information
fklassen committed Jan 19, 2018
2 parents 2d4c968 + 7b0a2fa commit ae73c23
Show file tree
Hide file tree
Showing 16 changed files with 274 additions and 148 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ addons:

matrix:
include:
- os: osx
osx_image: xcode8.2
compiler: clang
before_install:
- brew update
- brew install autogen
- os: linux
dist: trusty
compiler: gcc
addons:
apt:
packages:
- libpcap-dev
- autogen
- os: linux
dist: trusty
compiler: clang
env: CI_BUILD_PREFIX=scan-build-3.5
env: CI_BUILD_PREFIX=scan-build-3.9
addons:
apt:
packages:
- libpcap-dev
- clang-3.5
- clang-3.9
- autogen

script:
- autoreconf -iv > build.log 2>&1 || (cat build.log && exit 1)
Expand Down
75 changes: 47 additions & 28 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dnl $Id$
AC_PREREQ([2.69])

dnl Set version info here!
AC_INIT([tcpreplay],[4.2.7-beta1],
AC_INIT([tcpreplay],[4.3.0-beta1],
[https:/appneta/tcpreplay/issues],
[tcpreplay],
[http://tcpreplay.sourceforge.net/])
Expand All @@ -15,7 +15,8 @@ AM_MAINTAINER_MODE
AM_WITH_DMALLOC

dnl People building from GitHub need the same version of Autogen as I'm using
dnl or specify --disable-local-libopts
dnl or specify --disable-local-libopts to force using the locally-installed
dnl copy of libopts rather than the source in the `./liopts/` directory.
MAINTAINER_AUTOGEN_VERSION=5.18.4

AC_CONFIG_MACRO_DIR([m4])
Expand Down Expand Up @@ -171,21 +172,41 @@ AC_PATH_PROG(depmod, depmod, /sbin/depmod, $PATH:/sbin)
AC_PATH_PROG(insmod, insmod, /sbin/insmod, $PATH:/sbin)
AC_PATH_PROG(rmmod, rmmod, /sbin/rmmod, $PATH:/sbin)


dnl tcpreplay has (so far) been relying on leading-edge autogen.
dnl Therefore, by default:
dnl - use the version we ship with
dnl - do not install it
dnl - build a static copy (AC_DISABLE_SHARED - implicitly done earlier)
case "${enable_local_libopts+set}" in
set) ;;
*) enable_local_libopts=yes ;;
esac

case "${enable_libopts_install+set}" in
set) ;;
*) enable_libopts_install=no ;;
esac

dnl check autogen version
AUTOGEN_VERSION="unknown - man pages will not be built"
if test -n "${AUTOGEN}" ; then
AC_MSG_CHECKING(for autogen version >= 5.18.x)
${AUTOGEN} -v >autogen.version
AUTOGEN_VERSION=$(cat autogen.version | ${SED} 's|.* \([[0-9\.]]\{5,\}\).*|\1|')
AC_MSG_CHECKING(for autogen version >= ${MAINTAINER_AUTOGEN_VERSION})
AUTOGEN_VERSION=$(${AUTOGEN} -v | ${CUT} -d' ' -f 4)
AUTOGEN_MAJOR=$(echo ${AUTOGEN_VERSION} | ${CUT} -d '.' -f 1)
AUTOGEN_MINOR=$(echo ${AUTOGEN_VERSION} | ${CUT} -d '.' -f 2)
if ( test ${AUTOGEN_MAJOR} -eq 5 && test ${AUTOGEN_MINOR} -lt 18 ) || test ${AUTOGEN_MAJOR} -lt 5 ; then
AUTOGEN_BUILD=$(echo ${AUTOGEN_VERSION} | ${CUT} -d '.' -f 3)
if (test ${AUTOGEN_MAJOR} -eq 5 && test ${AUTOGEN_MINOR} -eq 18 && test ${AUTOGEN_BUILD} -lt 4) ||
(test ${AUTOGEN_MAJOR} -eq 5 && test ${AUTOGEN_MINOR} -lt 18) ||
test ${AUTOGEN_MAJOR} -lt 5 ; then
AC_MSG_RESULT(no)
AC_MSG_WARN([${AUTOGEN} is too old (${AUTOGEN_VERSION}) for building from source code. Please upgrade to 5.18.4)])
if test "x$enable_local_libopts" == "xno"; then
AC_MSG_ERROR([${AUTOGEN} is too old (${AUTOGEN_VERSION}) for building from source code. Upgrade to 5.18.4 or higher])
fi
AUTOGEN_VERSION="${AUTOGEN_VERSION} - downlevel"
else
AC_MSG_RESULT(yes)
fi
rm -f autogen.version

dnl Compare the installed version with the maintainer version if building from GitHub and not using system libopts
if test ! -f src/tcpreplay_opts.c && test "x$enable_local_libopts" = "xyes" ; then
Expand All @@ -195,7 +216,7 @@ if test -n "${AUTOGEN}" ; then
fi
else
if test ! -f src/tcpreplay_opts.c ; then
AC_MSG_ERROR([Please install GNU autogen $MAINTAINER_AUTOGEN_VERSION if you are building from GitHub. To avoid this message download source from http://tcpreplay.appneta.com/wiki/installation.html])
AC_MSG_ERROR([Please install GNU autogen $MAINTAINER_AUTOGEN_VERSION or higher if you are building from GitHub. To avoid this message download source from http://tcpreplay.appneta.com/wiki/installation.html])
fi
fi
AC_DEFINE([AUTOGEN_VERSION], [${AUTOGEN_VERSION}], [What version of autogen is installed on this system])
Expand Down Expand Up @@ -239,18 +260,26 @@ AC_CHECK_TYPE(u_int32_t, uint32_t)
AC_CHECK_TYPE(u_int64_t, uint64_t)

dnl OS X SDK 10.11 throws lots of unnecessary macro warnings
wno_format=""
wno_macro_redefined=""
case $host in
*-apple-darwin*)
AC_MSG_CHECKING(for $CC -Wno-macro-redefined)
OLD_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -Wno-macro-redefined"
wno_macro_redefined=""
CFLAGS="$CFLAGS -Wno-macro-redefined -Werror"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
int main(int argc, char *argv[]) { return(0); }]])],
[ AC_MSG_RESULT(yes)
wno_macro_redefined="-Wno-macro-redefined" ],
[ AC_MSG_RESULT(no) ])
CFLAGS="$OLD_CFLAGS $wno_macro_redefined"
CFLAGS="$CFLAGS -Wno-format -Werror"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
int main(int argc, char *argv[]) { return(0); }]])],
[ AC_MSG_RESULT(yes)
wno_format="-Wno-format" ],
[ AC_MSG_RESULT(no) ])
CFLAGS="$OLD_CFLAGS $wno_format"
;;
esac

Expand Down Expand Up @@ -352,7 +381,7 @@ AC_ARG_ENABLE(debug,
AC_HELP_STRING([--enable-debug], [Enable debugging code and support for the -d option]),
[ if test x$enableval = xyes; then
debug=yes
CFLAGS="${USER_CFLAGS} -g -O0 -std=gnu99 -Wall $wextra $wfatal_errors $wno_variadic_macros $wno_format_contains_nul"
CFLAGS="${USER_CFLAGS} -g -O0 -std=gnu99 -Wall $wextra $wfatal_errors $wno_variadic_macros $wno_format_contains_nul $wno_format"
# We may also want to add:
# -Wformat-security -Wswitch-default -Wunused-paramter -Wpadded"
debug_flag=DEBUG
Expand Down Expand Up @@ -847,6 +876,9 @@ AC_RUN_IFELSE([AC_LANG_PROGRAM([[
* returns zero if version >= 0.9.6
* or one otherwise
*/
if (strncmp(pcap_lib_version(), PCAP_TEST, 3) >= 0)
exit(0);
if (strncmp(pcap_lib_version(), PCAP_TEST, 5) >= 0) {
printf("%s ", pcap_lib_version());
exit(0);
Expand Down Expand Up @@ -898,6 +930,8 @@ extern const char pcap_version[[]]; /* double up since autoconf escapes things *
* returns zero if version >= 0.7.2
* or one otherwise
*/
if (strncmp(pcap_lib_version(), PCAP_TEST, 3) >= 0)
exit(0);
if (strncmp(pcap_version, PCAP_TEST, 5) >= 0)
exit(0);
Expand Down Expand Up @@ -1697,7 +1731,7 @@ AM_CONDITIONAL([ENABLE_TCPDUMP], test "$tcpdump_path" != "no" -a x$have_pcap_dum
if test x$tcpdump_path != xno -a x$have_pcap_dump_fopen = xyes ; then
AC_DEFINE([ENABLE_VERBOSE], [1], [Do we have tcpdump and pcap_dump_fopen()?])
else
AC_MSG_WARN([Your version of libpcap is too old for --verbose support])
AC_MSG_WARN([Your version of libpcap does not support --verbose])
fi

dnl No 'make test' when cross compile
Expand Down Expand Up @@ -1802,21 +1836,6 @@ else
AC_MSG_RESULT(no)
fi

dnl tcpreplay has (so far) been relying on leading-edge autogen.
dnl Therefore, by default:
dnl - use the version we ship with
dnl - do not install it
dnl - build a static copy (AC_DISABLE_SHARED - implicitly done earlier)
case "${enable_local_libopts+set}" in
set) ;;
*) enable_local_libopts=yes ;;
esac

case "${enable_libopts_install+set}" in
set) ;;
*) enable_libopts_install=no ;;
esac

LIBOPTS_CHECK(libopts)


Expand Down
8 changes: 7 additions & 1 deletion docs/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
05/27/2017 Version 4.2.7-beta1
01/18/2018 Version 4.3.0 beta1
- Travis CI build fails due to new build images (#432)
- Unable to build with libpcap 1.8.1 (#430)
- heap-buffer-overflow in get_l2protocol (#410)
- heap-buffer-overflow in packet2tree (#409)
- heap-buffer-overflow in get_l2len (#408)
- heap-buffer-overflow in flow_decode (#407)
- Fix sleep calculations when using multiple pcap files (#399)

05/10/2017 Version 4.2.6
Expand Down
20 changes: 18 additions & 2 deletions src/common/flows.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,18 @@ flow_entry_type_t flow_decode(flow_hash_table_t *fht, const struct pcap_pkthdr *
switch (datalink) {
case DLT_LINUX_SLL:
l2_len = 16;
if (pkthdr->caplen < l2_len)
return FLOW_ENTRY_INVALID;

sll_hdr = (sll_hdr_t *)pktdata;
ether_type = sll_hdr->sll_protocol;
break;

case DLT_PPP_SERIAL:
l2_len = 4;
if (pkthdr->caplen < l2_len)
return FLOW_ENTRY_INVALID;

ppp = (struct tcpr_pppserial_hdr *)pktdata;
if (ntohs(ppp->protocol) == 0x0021)
ether_type = htons(ETHERTYPE_IP);
Expand All @@ -200,6 +206,9 @@ flow_entry_type_t flow_decode(flow_hash_table_t *fht, const struct pcap_pkthdr *

case DLT_C_HDLC:
l2_len = 4;
if (pkthdr->caplen < l2_len)
return FLOW_ENTRY_INVALID;

hdlc_hdr = (hdlc_hdr_t *)pktdata;
ether_type = hdlc_hdr->protocol;
break;
Expand All @@ -212,6 +221,9 @@ flow_entry_type_t flow_decode(flow_hash_table_t *fht, const struct pcap_pkthdr *
break;

case DLT_JUNIPER_ETHER:
if (pkthdr->caplen < 5)
return FLOW_ENTRY_INVALID;

if (memcmp(pktdata, "MGC", 3))
warnx("No Magic Number found: %s (0x%x)",
pcap_datalink_val_to_description(datalink), datalink);
Expand All @@ -222,11 +234,15 @@ flow_entry_type_t flow_decode(flow_hash_table_t *fht, const struct pcap_pkthdr *
} else
l2_len = 4; /* no header extensions */

/* fall through */
case DLT_EN10MB:
/* set l2_len if we did not fell through */
if (l2_len == 0)
l2_len = sizeof(eth_hdr_t);

if (pkthdr->caplen < l2_len)
return FLOW_ENTRY_INVALID;

/* fall through */
case DLT_EN10MB:
ether_type = ntohs(((eth_hdr_t*)(pktdata + l2_len))->ether_type);

while (ether_type == ETHERTYPE_VLAN) {
Expand Down
Loading

0 comments on commit ae73c23

Please sign in to comment.