detect: prep for dynamic smlists arrays in sigs

Initialize Signature::init_data::smlists like normal, but before use
expand them if needed.
pull/3246/head
Victor Julien 9 years ago
parent bdb886bd68
commit 765b7a6b66

@ -280,6 +280,25 @@ static SigTableElmt *SigTableGet(char *name)
*/
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
{
if (list > 0 && (uint32_t)list >= s->init_data->smlists_array_size)
{
uint32_t old_size = s->init_data->smlists_array_size;
uint32_t new_size = (uint32_t)list + 1;
void *ptr = SCRealloc(s->init_data->smlists, (new_size * sizeof(SigMatch *)));
if (ptr == NULL)
abort();
s->init_data->smlists = ptr;
ptr = SCRealloc(s->init_data->smlists_tail, (new_size * sizeof(SigMatch *)));
if (ptr == NULL)
abort();
s->init_data->smlists_tail = ptr;
for (uint32_t i = old_size; i < new_size; i++) {
s->init_data->smlists[i] = NULL;
s->init_data->smlists_tail[i] = NULL;
}
s->init_data->smlists_array_size = new_size;
}
if (s->init_data->smlists[list] == NULL) {
s->init_data->smlists[list] = new;
s->init_data->smlists_tail[list] = new;
@ -1159,16 +1178,17 @@ Signature *SigAlloc (void)
SCFree(sig);
return NULL;
}
int lists = DetectBufferTypeMaxId();
SCLogDebug("smlists size %d", lists);
sig->init_data->smlists = SCCalloc(lists, sizeof(SigMatch *));
sig->init_data->smlists_array_size = DetectBufferTypeMaxId();
SCLogDebug("smlists size %u", sig->init_data->smlists_array_size);
sig->init_data->smlists = SCCalloc(sig->init_data->smlists_array_size, sizeof(SigMatch *));
if (sig->init_data->smlists == NULL) {
SCFree(sig->init_data);
SCFree(sig);
return NULL;
}
sig->init_data->smlists_tail = SCCalloc(lists, sizeof(SigMatch *));
sig->init_data->smlists_tail = SCCalloc(sig->init_data->smlists_array_size, sizeof(SigMatch *));
if (sig->init_data->smlists_tail == NULL) {
SCFree(sig->init_data->smlists_tail);
SCFree(sig->init_data);

@ -390,6 +390,7 @@ typedef struct SignatureInitData_ {
int prefilter_list;
uint32_t smlists_array_size;
/* holds all sm lists */
struct SigMatch_ **smlists;
/* holds all sm lists' tails */

Loading…
Cancel
Save