Coverage Report

Created: 2026-06-07 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/suricata7/src/datasets-string.c
Line
Count
Source
1
/* Copyright (C) 2017-2019 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
/**
19
 * \file
20
 *
21
 * \author Victor Julien <victor@inliniac.net>
22
 */
23
24
#include "suricata-common.h"
25
#include "conf.h"
26
#include "datasets.h"
27
#include "datasets-string.h"
28
#include "util-thash.h"
29
#include "util-print.h"
30
#include "util-base64.h"    // decode base64
31
#include "util-hash-lookup3.h"
32
#include "rust.h"
33
34
#if 0
35
static int StringAsAscii(const void *s, char *out, size_t out_size)
36
{
37
    const StringType *str = s;
38
    uint32_t offset = 0;
39
    PrintRawUriBuf(out, &offset, out_size, str->ptr, str->len);
40
    if (out[0] == '\0')
41
        return 0;
42
    strlcat(out, "\n", out_size);
43
    return strlen(out);
44
}
45
#endif
46
47
int StringAsBase64(const void *s, char *out, size_t out_size)
48
0
{
49
0
    const StringType *str = s;
50
51
0
    unsigned long len = Base64EncodeBufferSize(str->len);
52
0
    if (len + 2 > out_size) {
53
        // linefeed and final zero : signal we need more space
54
0
        return (int)len + 2;
55
0
    }
56
0
    if (Base64Encode((unsigned char *)str->ptr, str->len, (uint8_t *)out, &len) != SC_BASE64_OK)
57
0
        return 0;
58
59
0
    strlcat(out, "\n", out_size);
60
0
    return strlen(out);
61
0
}
62
63
int StringSet(void *dst, void *src)
64
112
{
65
112
    StringType *src_s = src;
66
112
    StringType *dst_s = dst;
67
112
    SCLogDebug("dst %p src %p, src_s->ptr %p src_s->len %u", dst, src, src_s->ptr, src_s->len);
68
69
112
    dst_s->len = src_s->len;
70
112
    dst_s->ptr = SCMalloc(dst_s->len);
71
112
    BUG_ON(dst_s->ptr == NULL);
72
112
    memcpy(dst_s->ptr, src_s->ptr, dst_s->len);
73
74
112
    dst_s->rep = src_s->rep;
75
112
    SCLogDebug("dst %p src %p, dst_s->ptr %p dst_s->len %u", dst, src, dst_s->ptr, dst_s->len);
76
112
    return 0;
77
112
}
78
79
bool StringCompare(void *a, void *b)
80
56.3k
{
81
56.3k
    const StringType *as = a;
82
56.3k
    const StringType *bs = b;
83
84
56.3k
    if (as->len != bs->len)
85
0
        return false;
86
87
56.3k
    return (memcmp(as->ptr, bs->ptr, as->len) == 0);
88
56.3k
}
89
90
uint32_t StringHash(uint32_t hash_seed, void *s)
91
57.0k
{
92
57.0k
    StringType *str = s;
93
57.0k
    return hashlittle_safe(str->ptr, str->len, hash_seed);
94
57.0k
}
95
96
// base data stays in hash
97
void StringFree(void *s)
98
2.96M
{
99
2.96M
    StringType *str = s;
100
2.96M
    SCFree(str->ptr);
101
2.96M
}