Fix a few memory issues.

remotes/origin/master-1.0.x
Victor Julien 16 years ago
parent 7e4377224a
commit 241db64dd7

@ -273,7 +273,7 @@ ConfYamlLoadFile(const char *filename)
* \brief Load configuration from a YAML string. * \brief Load configuration from a YAML string.
*/ */
void void
ConfYamlLoadString(const u_char *string, size_t len) ConfYamlLoadString(const char *string, size_t len)
{ {
yaml_parser_t parser; yaml_parser_t parser;
@ -281,7 +281,7 @@ ConfYamlLoadString(const u_char *string, size_t len)
fprintf(stderr, "Failed to initialize yaml parser.\n"); fprintf(stderr, "Failed to initialize yaml parser.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
yaml_parser_set_input_string(&parser, string, len); yaml_parser_set_input_string(&parser, (const unsigned char *)string, len);
ConfYamlParse(&parser); ConfYamlParse(&parser);
yaml_parser_delete(&parser); yaml_parser_delete(&parser);
} }
@ -303,7 +303,7 @@ default-log-dir: /tmp\n\
"; ";
ConfNode *node; ConfNode *node;
ConfYamlLoadString((u_char *)input, strlen(input)); ConfYamlLoadString(input, strlen(input));
node = ConfGetNode("rule-files"); node = ConfGetNode("rule-files");
if (node == NULL) if (node == NULL)
return 0; return 0;

@ -4,7 +4,7 @@
#define __CONF_YAML_LOADER_H__ #define __CONF_YAML_LOADER_H__
void ConfYamlLoadFile(const char *); void ConfYamlLoadFile(const char *);
void ConfYamlLoadString(const u_char *, size_t); void ConfYamlLoadString(const char *, size_t);
void ConfYamlRegisterTests(void); void ConfYamlRegisterTests(void);
#endif /* !__CONF_YAML_LOADER_H__ */ #endif /* !__CONF_YAML_LOADER_H__ */

@ -76,8 +76,20 @@ ConfHashComp(void *a, uint16_t a_len, void *b, uint16_t b_len)
static void ConfHashFree(void *data) static void ConfHashFree(void *data)
{ {
ConfNode *cn = (ConfNode *)data; ConfNode *cn = (ConfNode *)data;
if (cn == NULL)
return;
ConfNodeFree(cn); /** \todo VJ apparently the list that is free is also in the hash
* individually resulting in double free errors if we
* call ConfNodeFree (that clears the list) from this
* hash free function */
if (cn->name != NULL)
free(cn->name);
if (cn->val != NULL)
free(cn->val);
free(cn);
//ConfNodeFree(cn);
} }
/** /**

@ -651,6 +651,7 @@ error:
int DetectAddressSetup(DetectAddressHead *gh, char *s) { int DetectAddressSetup(DetectAddressHead *gh, char *s) {
DetectAddress *ad = NULL; DetectAddress *ad = NULL;
int r = 0; int r = 0;
char any = FALSE;
SCLogDebug("gh %p, s %s", gh, s); SCLogDebug("gh %p, s %s", gh, s);
@ -661,6 +662,9 @@ int DetectAddressSetup(DetectAddressHead *gh, char *s) {
goto error; goto error;
} }
if (ad->flags & ADDRESS_FLAG_ANY)
any = TRUE;
/* handle the not case, we apply the negation /* handle the not case, we apply the negation
* then insert the part(s) */ * then insert the part(s) */
if (ad->flags & ADDRESS_FLAG_NOT) { if (ad->flags & ADDRESS_FLAG_NOT) {
@ -691,7 +695,7 @@ int DetectAddressSetup(DetectAddressHead *gh, char *s) {
SCLogDebug("r %d",r); SCLogDebug("r %d",r);
/* if any, insert 0.0.0.0/0 and ::/0 as well */ /* if any, insert 0.0.0.0/0 and ::/0 as well */
if (r == 1 && ad->flags & ADDRESS_FLAG_ANY) { if (r == 1 && any == TRUE) {
SCLogDebug("adding 0.0.0.0/0 and ::/0 as we\'re handling \'any\'"); SCLogDebug("adding 0.0.0.0/0 and ::/0 as we\'re handling \'any\'");
ad = DetectAddressParseSingle("0.0.0.0/0"); ad = DetectAddressParseSingle("0.0.0.0/0");

@ -3625,7 +3625,7 @@ static int SigTest15Real (int mpm_type) {
ConfCreateContextBackup(); ConfCreateContextBackup();
ConfInit(); ConfInit();
ConfYamlLoadString((u_char *)dummy_conf_string, strlen(dummy_conf_string)); ConfYamlLoadString(dummy_conf_string, strlen(dummy_conf_string));
DetectEngineCtx *de_ctx = DetectEngineCtxInit(); DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) { if (de_ctx == NULL) {
@ -3642,7 +3642,6 @@ static int SigTest15Real (int mpm_type) {
} }
SigGroupBuild(de_ctx); SigGroupBuild(de_ctx);
//PatternMatchPrepare(mpm_ctx, mpm_type);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx,(void *)&det_ctx); DetectEngineThreadCtxInit(&th_v, (void *)de_ctx,(void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p); SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
@ -3654,7 +3653,6 @@ static int SigTest15Real (int mpm_type) {
SigGroupCleanup(de_ctx); SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx); SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx); DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
//PatternMatchDestroy(mpm_ctx);
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);
end: end:
ConfDeInit(); ConfDeInit();
@ -3692,7 +3690,7 @@ static int SigTest16Real (int mpm_type) {
ConfCreateContextBackup(); ConfCreateContextBackup();
ConfInit(); ConfInit();
ConfYamlLoadString((u_char *)dummy_conf_string, strlen(dummy_conf_string)); ConfYamlLoadString(dummy_conf_string, strlen(dummy_conf_string));
DetectEngineCtx *de_ctx = DetectEngineCtxInit(); DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) { if (de_ctx == NULL) {
@ -3760,7 +3758,7 @@ static int SigTest17Real (int mpm_type) {
ConfCreateContextBackup(); ConfCreateContextBackup();
ConfInit(); ConfInit();
ConfYamlLoadString((u_char *)dummy_conf_string, strlen(dummy_conf_string)); ConfYamlLoadString(dummy_conf_string, strlen(dummy_conf_string));
DetectEngineCtx *de_ctx = DetectEngineCtxInit(); DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) { if (de_ctx == NULL) {
@ -3898,7 +3896,7 @@ int SigTest19Real (int mpm_type) {
ConfCreateContextBackup(); ConfCreateContextBackup();
ConfInit(); ConfInit();
ConfYamlLoadString((u_char *)dummy_conf_string, strlen(dummy_conf_string)); ConfYamlLoadString(dummy_conf_string, strlen(dummy_conf_string));
DetectEngineCtx *de_ctx = DetectEngineCtxInit(); DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) { if (de_ctx == NULL) {
@ -3965,7 +3963,7 @@ static int SigTest20Real (int mpm_type) {
ConfCreateContextBackup(); ConfCreateContextBackup();
ConfInit(); ConfInit();
ConfYamlLoadString((u_char *)dummy_conf_string, strlen(dummy_conf_string)); ConfYamlLoadString(dummy_conf_string, strlen(dummy_conf_string));
DetectEngineCtx *de_ctx = DetectEngineCtxInit(); DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) { if (de_ctx == NULL) {

@ -160,7 +160,7 @@ int SCRuleVarsPositiveTest01(void)
ConfCreateContextBackup(); ConfCreateContextBackup();
ConfInit(); ConfInit();
ConfYamlLoadString((u_char *)dummy_conf_string, strlen(dummy_conf_string)); ConfYamlLoadString(dummy_conf_string, strlen(dummy_conf_string));
/* check for address-groups */ /* check for address-groups */
result &= (SCRuleVarsGetConfVar("$HOME_NET", SC_RULE_VARS_ADDRESS_GROUPS) != NULL && result &= (SCRuleVarsGetConfVar("$HOME_NET", SC_RULE_VARS_ADDRESS_GROUPS) != NULL &&
@ -219,7 +219,7 @@ int SCRuleVarsNegativeTest02(void)
ConfCreateContextBackup(); ConfCreateContextBackup();
ConfInit(); ConfInit();
ConfYamlLoadString((u_char *)dummy_conf_string, strlen(dummy_conf_string)); ConfYamlLoadString(dummy_conf_string, strlen(dummy_conf_string));
result &= (SCRuleVarsGetConfVar("$HOME_NETW", SC_RULE_VARS_ADDRESS_GROUPS) == NULL); result &= (SCRuleVarsGetConfVar("$HOME_NETW", SC_RULE_VARS_ADDRESS_GROUPS) == NULL);
result &= (SCRuleVarsGetConfVar("$home_net", SC_RULE_VARS_ADDRESS_GROUPS) == NULL); result &= (SCRuleVarsGetConfVar("$home_net", SC_RULE_VARS_ADDRESS_GROUPS) == NULL);
@ -245,12 +245,12 @@ int SCRuleVarsPositiveTest03(void)
ConfCreateContextBackup(); ConfCreateContextBackup();
ConfInit(); ConfInit();
ConfYamlLoadString((u_char *)dummy_conf_string, strlen(dummy_conf_string)); ConfYamlLoadString(dummy_conf_string, strlen(dummy_conf_string));
if ( (de_ctx = DetectEngineCtxInit()) == NULL) if ( (de_ctx = DetectEngineCtxInit()) == NULL)
goto end; goto end;
de_ctx->flags |= DE_QUIET; de_ctx->flags |= DE_QUIET;
/*
s = SigInit(de_ctx, "alert tcp $HTTP_SERVERS any -> any any (msg:\"Rule Vars Test\"; sid:1;)"); s = SigInit(de_ctx, "alert tcp $HTTP_SERVERS any -> any any (msg:\"Rule Vars Test\"; sid:1;)");
if (s == NULL) if (s == NULL)
goto end; goto end;
@ -340,7 +340,7 @@ int SCRuleVarsPositiveTest03(void)
if (s == NULL) if (s == NULL)
goto end; goto end;
SigFree(s); SigFree(s);
*/
s = SigInit(de_ctx, "alert tcp [![192.168.1.3,$EXTERNAL_NET],[$HTTP_SERVERS,!$HOME_NET],192.168.2.5] $HTTP_PORTS -> !$HTTP_SERVERS [80,[!$HTTP_PORTS,$ORACLE_PORTS]] (msg:\"Rule Vars Test\"; sid:1;)"); s = SigInit(de_ctx, "alert tcp [![192.168.1.3,$EXTERNAL_NET],[$HTTP_SERVERS,!$HOME_NET],192.168.2.5] $HTTP_PORTS -> !$HTTP_SERVERS [80,[!$HTTP_PORTS,$ORACLE_PORTS]] (msg:\"Rule Vars Test\"; sid:1;)");
if (s == NULL) if (s == NULL)
goto end; goto end;
@ -369,7 +369,7 @@ int SCRuleVarsNegativeTest04(void)
ConfCreateContextBackup(); ConfCreateContextBackup();
ConfInit(); ConfInit();
ConfYamlLoadString((u_char *)dummy_conf_string, strlen(dummy_conf_string)); ConfYamlLoadString(dummy_conf_string, strlen(dummy_conf_string));
if ( (de_ctx = DetectEngineCtxInit()) == NULL) if ( (de_ctx = DetectEngineCtxInit()) == NULL)
goto end; goto end;

Loading…
Cancel
Save