]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer: remove ALPROTO_TEST and tests 12051/head
authorPhilippe Antoine <pantoine@oisf.net>
Tue, 29 Oct 2024 10:00:15 +0000 (11:00 +0100)
committerPhilippe Antoine <pantoine@oisf.net>
Tue, 29 Oct 2024 10:00:15 +0000 (11:00 +0100)
These tests purpose seems to have been lost.
Registering a alproto with a parser function that always fails,
and just testing that AppLayerParserParse returned -1...
We would get the same result  without registering a parser function,
or using ALPROTO_FAILED as argument to AppLayerParserParse

The comment says "Test the deallocation of app layer parser memory
on occurrence of error in the parsing process."
but I do not see how this is tested.

src/app-layer-parser.c
src/app-layer-parser.h
src/app-layer-protos.c
src/app-layer-protos.h

index 48a6e47c2d9ea9dcb3f4d5679a0044c63e247e11..d1cacc572f40f3ba8463e465b57e8e7ac19d036e 100644 (file)
@@ -1768,60 +1768,6 @@ uint16_t AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag
 #ifdef UNITTESTS
 #include "util-unittest-helper.h"
 
-static AppLayerParserCtx alp_ctx_backup_unittest;
-
-typedef struct TestState_ {
-    uint8_t test;
-} TestState;
-
-/**
- *  \brief  Test parser function to test the memory deallocation of app layer
- *          parser of occurrence of an error.
- */
-static AppLayerResult TestProtocolParser(Flow *f, void *test_state, AppLayerParserState *pstate,
-        StreamSlice stream_slice, void *local_data)
-{
-    SCEnter();
-    SCReturnStruct(APP_LAYER_ERROR);
-}
-
-/** \brief Function to allocates the Test protocol state memory
- */
-static void *TestProtocolStateAlloc(void *orig_state, AppProto proto_orig)
-{
-    SCEnter();
-    void *s = SCMalloc(sizeof(TestState));
-    if (unlikely(s == NULL))
-        goto end;
-    memset(s, 0, sizeof(TestState));
- end:
-    SCReturnPtr(s, "TestState");
-}
-
-/** \brief Function to free the Test Protocol state memory
- */
-static void TestProtocolStateFree(void *s)
-{
-    SCFree(s);
-}
-
-static uint64_t TestGetTxCnt(void *state)
-{
-    /* single tx */
-    return 1;
-}
-
-static void TestStateTransactionFree(void *state, uint64_t tx_id)
-{
-    /* do nothing */
-}
-
-static void *TestGetTx(void *state, uint64_t tx_id)
-{
-    TestState *test_state = (TestState *)state;
-    return test_state;
-}
-
 void AppLayerParserRegisterProtocolUnittests(uint8_t ipproto, AppProto alproto,
                                   void (*RegisterUnittests)(void))
 {
@@ -1831,109 +1777,6 @@ void AppLayerParserRegisterProtocolUnittests(uint8_t ipproto, AppProto alproto,
     SCReturn;
 }
 
-void AppLayerParserBackupParserTable(void)
-{
-    SCEnter();
-    alp_ctx_backup_unittest = alp_ctx;
-    memset(&alp_ctx, 0, sizeof(alp_ctx));
-    SCReturn;
-}
-
-void AppLayerParserRestoreParserTable(void)
-{
-    SCEnter();
-    alp_ctx = alp_ctx_backup_unittest;
-    memset(&alp_ctx_backup_unittest, 0, sizeof(alp_ctx_backup_unittest));
-    SCReturn;
-}
-
-/**
- * \test Test the deallocation of app layer parser memory on occurrence of
- *       error in the parsing process.
- */
-static int AppLayerParserTest01(void)
-{
-    AppLayerParserBackupParserTable();
-
-    Flow *f = NULL;
-    uint8_t testbuf[] = { 0x11 };
-    uint32_t testlen = sizeof(testbuf);
-    TcpSession ssn;
-    AppLayerParserThreadCtx *alp_tctx = AppLayerParserThreadCtxAlloc();
-
-    memset(&ssn, 0, sizeof(ssn));
-
-    /* Register the Test protocol state and parser functions */
-    AppLayerParserRegisterParser(IPPROTO_TCP, ALPROTO_TEST, STREAM_TOSERVER, TestProtocolParser);
-    AppLayerParserRegisterStateFuncs(IPPROTO_TCP, ALPROTO_TEST,
-                          TestProtocolStateAlloc, TestProtocolStateFree);
-    AppLayerParserRegisterTxFreeFunc(IPPROTO_TCP, ALPROTO_TEST, TestStateTransactionFree);
-    AppLayerParserRegisterGetTx(IPPROTO_TCP, ALPROTO_TEST, TestGetTx);
-    AppLayerParserRegisterGetTxCnt(IPPROTO_TCP, ALPROTO_TEST, TestGetTxCnt);
-
-    f = UTHBuildFlow(AF_INET, "1.2.3.4", "4.3.2.1", 20, 40);
-    FAIL_IF_NULL(f);
-    f->protoctx = &ssn;
-    f->alproto = ALPROTO_TEST;
-    f->proto = IPPROTO_TCP;
-
-    StreamTcpInitConfig(true);
-
-    int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_TEST,
-                                STREAM_TOSERVER | STREAM_EOF, testbuf,
-                                testlen);
-    FAIL_IF(r != -1);
-
-    FAIL_IF(!(ssn.flags & STREAMTCP_FLAG_APP_LAYER_DISABLED));
-
-    AppLayerParserRestoreParserTable();
-    StreamTcpFreeConfig(true);
-    UTHFreeFlow(f);
-    PASS;
-}
-
-/**
- * \test Test the deallocation of app layer parser memory on occurrence of
- *       error in the parsing process for UDP.
- */
-static int AppLayerParserTest02(void)
-{
-    AppLayerParserBackupParserTable();
-
-    Flow *f = NULL;
-    uint8_t testbuf[] = { 0x11 };
-    uint32_t testlen = sizeof(testbuf);
-    AppLayerParserThreadCtx *alp_tctx = AppLayerParserThreadCtxAlloc();
-
-    /* Register the Test protocol state and parser functions */
-    AppLayerParserRegisterParser(IPPROTO_UDP, ALPROTO_TEST, STREAM_TOSERVER,
-                      TestProtocolParser);
-    AppLayerParserRegisterStateFuncs(IPPROTO_UDP, ALPROTO_TEST,
-                          TestProtocolStateAlloc, TestProtocolStateFree);
-    AppLayerParserRegisterTxFreeFunc(IPPROTO_UDP, ALPROTO_TEST, TestStateTransactionFree);
-    AppLayerParserRegisterGetTx(IPPROTO_UDP, ALPROTO_TEST, TestGetTx);
-    AppLayerParserRegisterGetTxCnt(IPPROTO_UDP, ALPROTO_TEST, TestGetTxCnt);
-
-    f = UTHBuildFlow(AF_INET, "1.2.3.4", "4.3.2.1", 20, 40);
-    FAIL_IF_NULL(f);
-    f->alproto = ALPROTO_TEST;
-    f->proto = IPPROTO_UDP;
-    f->protomap = FlowGetProtoMapping(f->proto);
-
-    StreamTcpInitConfig(true);
-
-    int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_TEST,
-                                STREAM_TOSERVER | STREAM_EOF, testbuf,
-                                testlen);
-    FAIL_IF(r != -1);
-
-    AppLayerParserRestoreParserTable();
-    StreamTcpFreeConfig(true);
-    UTHFreeFlow(f);
-    PASS;
-}
-
-
 void AppLayerParserRegisterUnittests(void)
 {
     SCEnter();
@@ -1951,9 +1794,6 @@ void AppLayerParserRegisterUnittests(void)
         }
     }
 
-    UtRegisterTest("AppLayerParserTest01", AppLayerParserTest01);
-    UtRegisterTest("AppLayerParserTest02", AppLayerParserTest02);
-
     SCReturn;
 }
 
index 64fc70205e70021e085a4b88a38e476859b39cbe..58ad4333563c775d2f00212bfdcf01c161fb3962 100644 (file)
@@ -315,8 +315,6 @@ void AppLayerParserTransactionsCleanup(Flow *f, const uint8_t pkt_dir);
 void AppLayerParserRegisterProtocolUnittests(uint8_t ipproto, AppProto alproto,
                                   void (*RegisterUnittests)(void));
 void AppLayerParserRegisterUnittests(void);
-void AppLayerParserBackupParserTable(void);
-void AppLayerParserRestoreParserTable(void);
 void UTHAppLayerParserStateGetIds(void *ptr, uint64_t *i1, uint64_t *i2, uint64_t *log, uint64_t *min);
 #endif
 
index e82d8688f557101fa562973e786c5df935b42761..03736554c7b6a449742c392d4b6d7eb7a9fcdff7 100644 (file)
@@ -70,9 +70,6 @@ const AppProtoStringTuple AppProtoStrings[ALPROTO_MAX] = {
     { ALPROTO_POP3, "pop3" },
     { ALPROTO_HTTP, "http" },
     { ALPROTO_FAILED, "failed" },
-#ifdef UNITTESTS
-    { ALPROTO_TEST, "test" },
-#endif
 };
 
 const char *AppProtoToString(AppProto alproto)
index 348203ac2f5306967d350a8a317c279bb0603d57..10b8959772c489d284ed2ee42eba75fa1508ff19 100644 (file)
@@ -72,9 +72,6 @@ enum AppProtoEnum {
     /* used by the probing parser when alproto detection fails
      * permanently for that particular stream */
     ALPROTO_FAILED,
-#ifdef UNITTESTS
-    ALPROTO_TEST,
-#endif /* UNITESTS */
     /* keep last */
     ALPROTO_MAX,
 };