X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/c1c3c77463d592cc576eaa491e604752044ca55a..refs/heads/tcpdump-4.9:/print-sflow.c diff --git a/print-sflow.c b/print-sflow.c index f3d6ff5f..dcaf28e8 100644 --- a/print-sflow.c +++ b/print-sflow.c @@ -12,18 +12,20 @@ * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * - * The SFLOW protocol as per http://www.sflow.org/developers/specifications.php - * * Original code by Carles Kishimoto * * Expansion and refactoring by Rick Jones */ +/* \summary: sFlow protocol printer */ + +/* specification: http://www.sflow.org/developers/specifications.php */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include "netdissect.h" #include "extract.h" @@ -879,6 +881,14 @@ sflow_print(netdissect_options *ndo, tptr = pptr; tlen = len; sflow_datagram = (const struct sflow_datagram_t *)pptr; + if (len < sizeof(struct sflow_datagram_t)) { + ND_TCHECK(sflow_datagram->version); + ND_PRINT((ndo, "sFlowv%u", EXTRACT_32BITS(sflow_datagram->version))); + ND_PRINT((ndo, " [length %u < %zu]", + len, sizeof(struct sflow_datagram_t))); + ND_PRINT((ndo, " (invalid)")); + return; + } ND_TCHECK(*sflow_datagram); /* @@ -914,6 +924,8 @@ sflow_print(netdissect_options *ndo, /* skip Common header */ tptr += sizeof(const struct sflow_datagram_t); + + if(tlen <= sizeof(const struct sflow_datagram_t)) goto trunc; tlen -= sizeof(const struct sflow_datagram_t); while (nsamples > 0 && tlen > 0) {