• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jasonish / suricata / 22802647571

07 Mar 2026 04:23PM UTC coverage: 75.827% (-3.4%) from 79.233%
22802647571

push

github

jasonish
github-ci: add schema ordering check for yaml schema

253365 of 334137 relevant lines covered (75.83%)

3384729.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.55
/src/detect-base64-data.c
1
/* Copyright (C) 2015 Open Information Security Foundation
2
 *
3
 * You can copy, redistribute or modify this Program under the terms of
4
 * the GNU General Public License version 2 as published by the Free
5
 * Software Foundation.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * version 2 along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
 * 02110-1301, USA.
16
 */
17

18
#include "suricata-common.h"
19
#include "detect.h"
20
#include "detect-engine.h"
21
#include "detect-engine-content-inspection.h"
22
#include "detect-parse.h"
23
#include "detect-base64-data.h"
24
#include "detect-engine-build.h"
25

26
#include "util-unittest.h"
27

28
static int DetectBase64DataSetup(DetectEngineCtx *, Signature *, const char *);
29
#ifdef UNITTESTS
30
static void DetectBase64DataRegisterTests(void);
31
#endif
32

33
void DetectBase64DataRegister(void)
34
{
2,193✔
35
    sigmatch_table[DETECT_BASE64_DATA].name = "base64_data";
2,193✔
36
    sigmatch_table[DETECT_BASE64_DATA].desc =
2,193✔
37
        "Content match base64 decoded data.";
2,193✔
38
    sigmatch_table[DETECT_BASE64_DATA].url =
2,193✔
39
        "/rules/base64-keywords.html#base64-data";
2,193✔
40
    sigmatch_table[DETECT_BASE64_DATA].Setup = DetectBase64DataSetup;
2,193✔
41
#ifdef UNITTESTS
3✔
42
    sigmatch_table[DETECT_BASE64_DATA].RegisterTests =
3✔
43
        DetectBase64DataRegisterTests;
3✔
44
#endif
3✔
45
    sigmatch_table[DETECT_BASE64_DATA].flags |= SIGMATCH_NOOPT;
2,193✔
46
}
2,193✔
47

48
static int DetectBase64DataSetup(DetectEngineCtx *de_ctx, Signature *s,
49
    const char *str)
50
{
92✔
51
    SigMatch *pm = NULL;
92✔
52

53
    /* Check for a preceding base64_decode. */
54
    pm = SCDetectGetLastSMFromLists(s, DETECT_BASE64_DECODE, -1);
92✔
55
    if (pm == NULL) {
92✔
56
        SCLogError("\"base64_data\" keyword seen without preceding base64_decode.");
×
57
        return -1;
×
58
    }
×
59

60
    s->init_data->list = DETECT_SM_LIST_BASE64_DATA;
92✔
61
    return 0;
92✔
62
}
92✔
63

64
#ifdef UNITTESTS
65

66
static int g_file_data_buffer_id = 0;
67

68
static int DetectBase64DataSetupTest01(void)
69
{
1✔
70
    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
1✔
71
    FAIL_IF_NULL(de_ctx);
1✔
72

73
    de_ctx->flags |= DE_QUIET;
1✔
74
    Signature *s = DetectEngineAppendSig(de_ctx,
1✔
75
            "alert smtp any any -> any any (msg:\"DetectBase64DataSetupTest\"; "
1✔
76
            "base64_decode; base64_data; content:\"content\"; sid:1; rev:1;)");
1✔
77
    FAIL_IF_NULL(s);
1✔
78

79
    SigMatch *sm = s->init_data->smlists[DETECT_SM_LIST_PMATCH];
1✔
80
    FAIL_IF_NULL(sm);
1✔
81
    FAIL_IF_NOT(sm->type == DETECT_BASE64_DECODE);
1✔
82
    FAIL_IF_NULL(s->init_data->smlists[DETECT_SM_LIST_BASE64_DATA]);
1✔
83

84
    DetectEngineCtxFree(de_ctx);
1✔
85
    PASS;
1✔
86
}
1✔
87

88
/**
89
 * \test Test that the list can be changed to post-detection lists
90
 *     after the base64 keyword.
91
 */
92
static int DetectBase64DataSetupTest04(void)
93
{
1✔
94
    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
1✔
95
    FAIL_IF_NULL(de_ctx);
1✔
96

97
    de_ctx->flags |= DE_QUIET;
1✔
98
    Signature *s = DetectEngineAppendSig(de_ctx,
1✔
99
            "alert tcp any any -> any any (msg:\"some b64thing\"; flow:established,from_server; "
1✔
100
            "file_data; content:\"sometext\"; fast_pattern; base64_decode:relative; base64_data; "
1✔
101
            "content:\"foobar\"; nocase; tag:session,120,seconds; sid:1111111; rev:1;)");
1✔
102
    FAIL_IF_NULL(s);
1✔
103

104
    DetectEngineCtxFree(de_ctx);
1✔
105
    PASS;
1✔
106
}
1✔
107

108
static void DetectBase64DataRegisterTests(void)
109
{
1✔
110
    g_file_data_buffer_id = DetectBufferTypeGetByName("file_data");
1✔
111

112
    UtRegisterTest("DetectBase64DataSetupTest01", DetectBase64DataSetupTest01);
1✔
113
    UtRegisterTest("DetectBase64DataSetupTest04", DetectBase64DataSetupTest04);
1✔
114
}
1✔
115
#endif /* UNITTESTS */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc