]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
protodetect: opposing side cannot change protocol
authorPhilippe Antoine <contact@catenacyber.fr>
Fri, 16 Jul 2021 12:22:28 +0000 (14:22 +0200)
committerVictor Julien <vjulien@oisf.net>
Fri, 12 Nov 2021 14:21:07 +0000 (15:21 +0100)
Ticket: #4562

As the data which triggered the opposing side
was the same protocol and not another one,
that means the protocol change failed.

Prevents a memory leak in later call of AppLayerParserParse
which would allocate a new state and leak the old one

src/app-layer.c

index ffb8ecdb7a4564e414f9786cbc9c6556d49f6af7..6fc0339e1fc38f7f8b04294acd8f1b87cf120bd2 100644 (file)
@@ -397,6 +397,15 @@ static int TCPProtoDetect(ThreadVars *tv,
                 DisableAppLayer(tv, f, p);
                 SCReturnInt(-1);
             }
+            if (FlowChangeProto(f)) {
+                /* We have the first data which requested a protocol change from P1 to P2
+                 * even if it was not recognized at first as being P1
+                 * As the second data was recognized as P1, the protocol did not change !
+                 */
+                FlowUnsetChangeProtoFlag(f);
+                AppLayerDecoderEventsSetEventRaw(&p->app_layer_events,
+                                                 APPLAYER_UNEXPECTED_PROTOCOL);
+            }
         }
 
         /* if the parser operates such that it needs to see data from