From ba205a04ba4f759e36463022b12a882729868271 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sun, 30 Sep 2007 20:29:06 -0700 Subject: [PATCH] Fix issues with non-zero-terminated URLs in urlIsMatched. Thanks to phuel. darcs-hash:20071001032906-4cc09-c8858ba40ac3f3833bf43a73c49c6e458897be44.gz --- forbidden.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/forbidden.c b/forbidden.c index 460ed28..0aa659c 100644 --- a/forbidden.c +++ b/forbidden.c @@ -362,9 +362,29 @@ urlIsMatched(char *url, int length, DomainPtr *domains, regex_t *regex) domain++; } } + if(regex) { - if(!regexec(regex, url, 0, NULL, 0)) - return 1; + /* url is not necessarily 0-terminated */ + char smallcopy[50]; + char *urlcopy; + int rc; + + if(length < 50) { + urlcopy = smallcopy; + } else { + urlcopy = malloc(length + 1); + if(urlcopy == NULL) + return 0; + } + memcpy(urlcopy, url, length); + urlcopy[length] = '\0'; + + rc = regexec(regex, urlcopy, 0, NULL, 0); + + if(urlcopy != smallcopy) + free(urlcopy); + + return !rc; } return 0; } -- 2.11.4.GIT