From e29b755c6dd168fd8459d00f90fd5ec6ef2f7355 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sat, 24 May 2014 13:49:17 +0800 Subject: [PATCH] fix the issue introduced by newline --- src/acl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/acl.c b/src/acl.c index 27c80524..ca16f59f 100644 --- a/src/acl.c +++ b/src/acl.c @@ -10,6 +10,7 @@ static void parse_addr_cidr(const char *str, char **host, int *cidr) { int ret = -1, n = 0; char *pch; + pch = strchr(str, '/'); while (pch != NULL) { @@ -53,6 +54,13 @@ int init_acl(const char *path) { if (fgets(line, 256, f)) { + // Trim the newline + int len = strlen(line); + if (len > 0 && line[len - 1] == '\n') + { + line[len - 1] = '\0'; + } + char *host = NULL; int cidr; parse_addr_cidr(line, &host, &cidr); @@ -111,6 +119,7 @@ int acl_contains_domain(const char* domain) if (match) return 1; } + return 0; }