Fix a memory error in the addresslist parsing code. Add a functions aimed at speeding up the signature initialization code.

remotes/origin/master-1.0.x
Victor Julien 17 years ago
parent b50fc8aecd
commit 84087e7077

@ -51,12 +51,29 @@ void DetectAddressGroupFree(DetectAddressGroup *ag) {
}
}
/* used to see if the exact same address group exists in the list
* returns a ptr to the match, or NULL if no match
*/
DetectAddressGroup *DetectAddressGroupLookup(DetectAddressGroup *head, DetectAddressData *ad) {
DetectAddressGroup *cur;
if (head != NULL) {
for (cur = head; cur != NULL; cur = cur->next) {
if (DetectAddressCmp(cur->ad, ad) == ADDRESS_EQ)
return cur;
}
}
return NULL;
}
void DetectAddressGroupPrintList(DetectAddressGroup *head) {
DetectAddressGroup *cur;
printf("list:\n");
if (head != NULL) {
for (cur = head; cur != NULL; cur = cur->next) {
printf("SIGS %6u ", cur->sh ? cur->sh->sig_cnt : 0);
DetectAddressDataPrint(cur->ad);
}
}
@ -79,6 +96,22 @@ void DetectAddressGroupCleanupList (DetectAddressGroup *head) {
head = NULL;
}
int DetectAddressGroupAppend(DetectAddressGroup **head, DetectAddressGroup *ag) {
DetectAddressGroup *cur, *prev_cur = NULL;
if (*head != NULL) {
for (cur = *head; cur != NULL; cur = cur->next) {
prev_cur = cur;
}
ag->prev = prev_cur;
prev_cur->next = ag;
} else {
*head = ag;
}
return 0;
}
/* helper functions for DetectAddressGroupInsert:
* set & get the head ptr
*/
@ -386,7 +419,7 @@ int DetectAddressGroupMergeNot(DetectAddressGroupsHead *gh, DetectAddressGroupsH
/* step 2: pull the address blocks that match our 'not' blocks */
for (ag = ghn->ipv4_head; ag != NULL; ag = ag->next) {
for (ag2 = gh->ipv4_head; ag2 != NULL; ag2 = ag2->next) {
for (ag2 = gh->ipv4_head; ag2 != NULL; ) {
r = DetectAddressCmp(ag->ad,ag2->ad);
if (r == ADDRESS_EQ || r == ADDRESS_EB) { /* XXX more ??? */
if (ag2->prev == NULL) {
@ -398,8 +431,12 @@ int DetectAddressGroupMergeNot(DetectAddressGroupsHead *gh, DetectAddressGroupsH
if (ag2->next != NULL) {
ag2->next->prev = ag2->prev;
}
/* store the next ptr and remove the group */
DetectAddressGroup *next_ag2 = ag2->next;
DetectAddressGroupFree(ag2);
ag2 = next_ag2;
} else {
ag2 = ag2->next;
}
}
}
@ -428,7 +465,7 @@ error:
return -1;
}
int DetectAddressGroupParse(DetectAddressGroupsHead *gh, char *s) {
int DetectAddressGroupParse(DetectAddressGroupsHead *gh, char *str) {
int r;
DetectAddressGroupsHead *ghn = DetectAddressGroupsHeadInit();
@ -436,7 +473,7 @@ int DetectAddressGroupParse(DetectAddressGroupsHead *gh, char *s) {
goto error;
}
r = DetectAddressGroupParse2(gh,ghn,s,/* start with negate no */0);
r = DetectAddressGroupParse2(gh,ghn,str,/* start with negate no */0);
if (r < 0) {
goto error;
}

@ -60,7 +60,10 @@ int DetectAddressGroupSetup(DetectAddressGroupsHead *, char *);
int DetectAddressCmp(DetectAddressData *, DetectAddressData *);
DetectAddressData *DetectAddressParse(char *);
DetectAddressGroup *DetectAddressLookupGroup(DetectAddressGroupsHead *, Address *);
int DetectAddressGroupParse(DetectAddressGroupsHead *gh, char *s);
int DetectAddressGroupParse(DetectAddressGroupsHead *, char *);
DetectAddressGroup *DetectAddressGroupInit(void);
int DetectAddressGroupAppend(DetectAddressGroup **head, DetectAddressGroup *ag);
DetectAddressGroup *DetectAddressGroupLookup(DetectAddressGroup *head, DetectAddressData *ad);
#endif /* __DETECT_ADDRESS_H__ */

@ -233,6 +233,7 @@ int SigParseAddress(Signature *s, const char *addrstr, char flag) {
//printf("addr \"%s\"\n", addrstr);
}
/* pass on to the address(list) parser */
if (flag == 0) {
if (DetectAddressGroupParse(&s->src,addr) < 0) {
goto error;

Loading…
Cancel
Save