From: Victor Julien Date: Sat, 20 Apr 2024 10:57:41 +0000 (+0200) Subject: decode/tcp: improve pointer hygene X-Git-Tag: suricata-8.0.0-beta1~1362 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86a363b1bcf478f19ab355efb3ad1a40e4d24997;p=thirdparty%2Fsuricata.git decode/tcp: improve pointer hygene Avoid NULL pointer calculations. --- diff --git a/src/decode-tcp.c b/src/decode-tcp.c index 558d005605..dd03f794d9 100644 --- a/src/decode-tcp.c +++ b/src/decode-tcp.c @@ -138,12 +138,11 @@ static void DecodeTCPOptions(Packet *p, const uint8_t *pkt, uint16_t pktlen) break; case TCP_OPT_SACK: SCLogDebug("SACK option, len %u", olen); - if ((olen != 2) && - (olen < TCP_OPT_SACK_MIN_LEN || - olen > TCP_OPT_SACK_MAX_LEN || - !((olen - 2) % 8 == 0))) - { - ENGINE_SET_EVENT(p,TCP_OPT_INVALID_LEN); + if (olen == 2) { + /* useless, but common empty SACK record */ + } else if (olen < TCP_OPT_SACK_MIN_LEN || olen > TCP_OPT_SACK_MAX_LEN || + !((olen - 2) % 8 == 0)) { + ENGINE_SET_EVENT(p, TCP_OPT_INVALID_LEN); } else { if (p->l4.vars.tcp.sack_set) { ENGINE_SET_EVENT(p,TCP_OPT_DUPLICATE);