Fix msg parsing.

remotes/origin/master-1.0.x
Victor Julien 15 years ago
parent e458b2a26e
commit 8b8e2fef2d

@ -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;
}

Loading…
Cancel
Save