]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
decode/tcp: improve pointer hygene
authorVictor Julien <vjulien@oisf.net>
Sat, 20 Apr 2024 10:57:41 +0000 (12:57 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 26 Apr 2024 18:59:45 +0000 (20:59 +0200)
Avoid NULL pointer calculations.

src/decode-tcp.c

index 558d005605a7faa687b7515a82d95745348ef58e..dd03f794d95385dd52926a5293ccd494f8f1a96f 100644 (file)
@@ -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);