From: Victor Julien Date: Wed, 19 Sep 2018 15:07:01 +0000 (+0200) Subject: decode/template: minor updates X-Git-Tag: suricata-4.1.0-rc2~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d0fc67560cbd6a15f2e3b4ffb8f46b31a8e0005;p=thirdparty%2Fsuricata.git decode/template: minor updates --- diff --git a/src/decode-template.c b/src/decode-template.c index be7acfe1b1..f233106695 100644 --- a/src/decode-template.c +++ b/src/decode-template.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Open Information Security Foundation +/* Copyright (C) 2015-2018 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -36,11 +36,8 @@ #include "decode-events.h" #include "decode-template.h" -#include "util-unittest.h" -#include "util-debug.h" - /** - * \brief Function to decode XXX packets + * \brief Function to decode TEMPLATE packets * \param tv thread vars * \param dtv decoder thread vars * \param p packet @@ -78,12 +75,14 @@ int DecodeTEMPLATE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, /* in this example it's clear that hdr_len can't be bigger than * 'len', but in more complex cases checking that we can't underflow * len is very important - if (hdr_len < len) { + if (hdr_len >= len) { + ENGINE_SET_EVENT(p,TEMPLATE_MALFORMED_HDRLEN); + return TM_ECODE_FAILED; + } */ /* invoke the next decoder on the remainder of the data */ return DecodeUDP(tv, dtv, p, (uint8_t *)pkt + hdr_len, len - hdr_len, pq); - //} } else { //ENGINE_SET_EVENT(p,TEMPLATE_UNSUPPORTED_PROTOCOL); return TM_ECODE_FAILED; diff --git a/src/decode-template.h b/src/decode-template.h index b6a976e0e4..5ee42e8cfe 100644 --- a/src/decode-template.h +++ b/src/decode-template.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Open Information Security Foundation +/* Copyright (C) 2015-2018 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -28,6 +28,9 @@ #include "decode.h" #include "threadvars.h" +/* Header layout. Keep things like alignment and endianess in + * mind while constructing this. */ + typedef struct TemplateHdr_ { uint8_t proto; uint8_t pad0;