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

OISF / suricata / 23374838686

21 Mar 2026 07:29AM UTC coverage: 59.341% (-20.0%) from 79.315%
23374838686

Pull #15075

github

web-flow
Merge 90b4e834f into 6587e363a
Pull Request #15075: Stack 8001 v16.4

38 of 70 new or added lines in 10 files covered. (54.29%)

34165 existing lines in 563 files now uncovered.

119621 of 201584 relevant lines covered (59.34%)

650666.92 hits per line

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

75.64
/src/feature.c
1
/* Copyright (C) 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 Jeff Lucovsky <jeff@lucovsky.org>
22
 *
23
 * Implements feature tracking
24
 */
25

26
#include "suricata-common.h"
27
#include "feature.h"
28
#include "threads.h"
29

30
#include "util-debug.h"
31
#include "util-hashlist.h"
32

33
typedef struct FeatureEntryType {
34
        const char *feature;
35
} FeatureEntryType;
36

37
static SCMutex feature_table_mutex = SCMUTEX_INITIALIZER;
38
static HashListTable *feature_hash_table;
39

40
static uint32_t FeatureHashFunc(HashListTable *ht, void *data,
41
                                uint16_t datalen)
42
{
3,961✔
43
    FeatureEntryType *f = (FeatureEntryType *)data;
3,961✔
44
    uint32_t hash = 0;
3,961✔
45
    size_t len = strlen(f->feature);
3,961✔
46

47
    for (size_t i = 0; i < len; i++)
47,013✔
48
        hash += u8_tolower((unsigned char)f->feature[i]);
43,052✔
49

50
    return (hash % ht->array_size);
3,961✔
51
}
3,961✔
52

53
static char FeatureHashCompareFunc(void *data1, uint16_t datalen1,
54
                                   void *data2, uint16_t datalen2)
55
{
3,384✔
56
    FeatureEntryType *f1 = (FeatureEntryType *)data1;
3,384✔
57
    FeatureEntryType *f2 = (FeatureEntryType *)data2;
3,384✔
58

59
    if (f1 == NULL || f2 == NULL)
3,384✔
60
        return 0;
×
61

62
    if (f1->feature == NULL || f2->feature == NULL)
3,384✔
63
        return 0;
×
64

65
    return strcmp(f1->feature, f2->feature) == 0;
3,384✔
66
}
3,384✔
67

68
static void FeatureHashFreeFunc(void *data)
69
{
4✔
70
    FeatureEntryType *f = data;
4✔
71
    if (f->feature) {
4✔
72
        SCFree((void *)f->feature);
4✔
73
    }
4✔
74
    SCFree(data);
4✔
75
}
4✔
76

77
static void FeatureInit(void) {
2✔
78
    feature_hash_table = HashListTableInit(256, FeatureHashFunc,
2✔
79
                                           FeatureHashCompareFunc,
2✔
80
                                           FeatureHashFreeFunc);
2✔
81

82
    if (!feature_hash_table) {
2✔
83
        FatalError("Unable to allocate feature hash table.");
×
84
    }
×
85
}
2✔
86

87
static void FeatureAddEntry(const char *feature_name)
88
{
9✔
89
    int rc;
9✔
90

91
    FeatureEntryType *feature = SCCalloc(1, sizeof(*feature));
9✔
92
    if (!feature) {
9✔
93
        FatalError("Unable to allocate feature entry memory.");
×
94
    }
×
95

96
    feature->feature = SCStrdup(feature_name);
9✔
97
    if (feature->feature) {
9✔
98
        rc = HashListTableAdd(feature_hash_table, feature, sizeof(*feature));
9✔
99
        if (rc == 0)
9✔
100
            return;
5✔
101
    }
9✔
102

103
    FeatureHashFreeFunc(feature);
4✔
104
}
4✔
105

106
void ProvidesFeature(const char *feature_name)
107
{
9✔
108
    FeatureEntryType f = { feature_name };
9✔
109

110
    SCMutexLock(&feature_table_mutex);
9✔
111

112
    FeatureEntryType *feature = HashListTableLookup(feature_hash_table, &f, sizeof(f));
9✔
113

114
    if (!feature) {
9✔
115
        FeatureAddEntry(feature_name);
9✔
116
    }
9✔
117

118
    SCMutexUnlock(&feature_table_mutex);
9✔
119
}
9✔
120

121
bool SCRequiresFeature(const char *feature_name)
122
{
4,062✔
123
    FeatureEntryType f = { feature_name };
4,062✔
124

125
    SCMutexLock(&feature_table_mutex);
4,062✔
126
    FeatureEntryType *feature = HashListTableLookup(feature_hash_table, &f, sizeof(f));
4,062✔
127
    SCMutexUnlock(&feature_table_mutex);
4,062✔
128
    return feature != NULL;
4,062✔
129
}
4,062✔
130

131
void FeatureTrackingRelease(void)
UNCOV
132
{
×
UNCOV
133
    if (feature_hash_table != NULL) {
×
UNCOV
134
        HashListTableFree(feature_hash_table);
×
UNCOV
135
        feature_hash_table = NULL;
×
UNCOV
136
    }
×
UNCOV
137
}
×
138

139
void FeatureDump(void)
UNCOV
140
{
×
UNCOV
141
    HashListTableBucket *hb = HashListTableGetListHead(feature_hash_table);
×
UNCOV
142
    for (; hb != NULL; hb = HashListTableGetListNext(hb)) {
×
UNCOV
143
        FeatureEntryType *f = HashListTableGetListData(hb);
×
UNCOV
144
        printf("provided feature name: %s\n", f->feature);
×
UNCOV
145
    }
×
UNCOV
146
}
×
147
void FeatureTrackingRegister(void)
148
{
2✔
149
    FeatureInit();
2✔
150
}
2✔
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