make regex work on null-containing strings by replacing null's with 0xff

This commit is contained in:
Christoph Sarnowski 2015-01-18 23:10:34 +01:00
parent 88af6ebaee
commit 436661a406

16
probe.c
View File

@ -223,12 +223,22 @@ static int is_tls_protocol(const char *p, int len, struct proto *proto)
static int regex_probe(const char *p, int len, struct proto *proto)
{
char *str;
regex_t **probe = proto->data;
regmatch_t pos = { 0, len };
for (; *probe && regexec(*probe, p, 0, &pos, REG_STARTEND); probe++)
int i;
str = (char *)malloc(len+1);
str[len] = 0;
for(i=0;i<len;i++){
if (p[i]){
str[i] = p[i];
} else {
str[i] = 0xff;
}
}
for (; *probe && regexec(*probe, str, 0, &pos, REG_STARTEND); probe++)
/* try them all */;
free(str);
return (*probe != NULL);
}