From 8b8e2fef2d77a7409d78b2f3d4b2b9d7eef6a856 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sat, 31 Oct 2009 17:53:08 +0100 Subject: [PATCH] Fix msg parsing. --- src/detect-msg.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/detect-msg.c b/src/detect-msg.c index ae1e7d8fc4..813aee0767 100644 --- a/src/detect-msg.c +++ b/src/detect-msg.c @@ -64,7 +64,7 @@ int DetectMsgSetup (DetectEngineCtx *de_ctx, Signature *s, SigMatch *m, char *ms str[i] != '\\' && str[i] != '\"') { - printf("DetectMsgSetup:%c does not need to be escaped but is\n",str[i]); + printf("DetectMsgSetup: %c does not need to be escaped but is\n" ,str[i]); } escape = 0; converted = 1; @@ -88,18 +88,16 @@ int DetectMsgSetup (DetectEngineCtx *de_ctx, Signature *s, SigMatch *m, char *ms if (converted) { len = x; + str[len] = '\0'; } } - s->msg = malloc(len); - + s->msg = malloc(len + 1); if (s->msg == NULL) goto error; - memset(s->msg, 0, sizeof(s->msg)); + strncpy(s->msg, str, len + 1); - strncpy(s->msg, str, len); - //printf("s->msg %s strlen(s->msg) %i str %s strlen(str) %i len %i\n",s->msg,strlen(s->msg),str,strlen(str),len); free(str); return 0; @@ -121,21 +119,20 @@ static int DetectMsgParseTest01(void) goto end; sig = SigInit(de_ctx, "alert tcp any any -> any any (msg:\"flow stateless to_server\"; flow:stateless,to_server; content:\"flowstatelesscheck\"; classtype:bad-unknown; sid: 40000002; rev: 1;)"); - if(sig == NULL) goto end; - if (memcmp(sig->msg, teststringparsed, strlen(sig->msg)) != 0) { - printf("got %s: expected: %s",sig->msg,teststringparsed); + if (strcmp(sig->msg, teststringparsed) != 0) { + printf("got \"%s\", expected: \"%s\": ", sig->msg, teststringparsed); goto end; - }else{ - result = 1; } - SigFree(sig); - DetectEngineCtxFree(de_ctx); - + result = 1; end: + if (sig != NULL) + SigFree(sig); + if (de_ctx != NULL) + DetectEngineCtxFree(de_ctx); return result; } @@ -149,21 +146,20 @@ static int DetectMsgParseTest02(void) goto end; sig = SigInit(de_ctx, "alert tcp any any -> any any (msg:\"msg escape tests \\w\\x\\y\\'\\\"\\\\;\\:\"; flow:to_server,established; content:\"blah\"; uricontent:\"/blah/\"; sid: 100;)"); - if(sig == NULL) goto end; - if (memcmp(sig->msg, teststringparsed, strlen(sig->msg)) != 0) { - printf("got %s: expected: %s",sig->msg,teststringparsed); + if (strcmp(sig->msg, teststringparsed) != 0) { + printf("got \"%s\", expected: \"%s\": ",sig->msg, teststringparsed); goto end; - }else{ - result = 1; } - SigFree(sig); - DetectEngineCtxFree(de_ctx); - + result = 1; end: + if (sig != NULL) + SigFree(sig); + if (de_ctx != NULL) + DetectEngineCtxFree(de_ctx); return result; }