Browse code

strip spaces from URL before checking that it is a URL

git-svn: trunk@4215

Török Edvin authored on 2008/10/01 18:56:54
Showing 2 changed files
... ...
@@ -995,10 +995,12 @@ static inline int validate_uri_ialpha(const char *start, const char *end)
995 995
  */
996 996
 static int isURL(const struct phishcheck* pchk,const char* URL, int accept_anyproto)
997 997
 {
998
+	size_t len;
998 999
 	const char *start = NULL, *p, *q;
999 1000
 	if(!URL)
1000 1001
 		return 0;
1001 1002
 
1003
+	while (*URL == ' ') URL++;
1002 1004
 	switch (URL[0]) {
1003 1005
 		case 'h':
1004 1006
 			if (strncmp(URL, https, https_len) == 0)
... ...
@@ -1045,7 +1047,9 @@ static int isURL(const struct phishcheck* pchk,const char* URL, int accept_anypr
1045 1045
 	} while(q);
1046 1046
 	if (p == start) /* must have at least one dot in the URL */
1047 1047
 		return 0;
1048
-	return !!in_tld_set(p, strlen(p));
1048
+	len = strlen(p);
1049
+	while (len > 1 && p[len-1] == ' ') len--;
1050
+	return !!in_tld_set(p, len);
1049 1051
 }
1050 1052
 
1051 1053
 /*
... ...
@@ -172,7 +172,10 @@ static const struct rtest {
172 172
 } rtests[] = {
173 173
 	{NULL,"http://fake.example.com","=====key.com",0},
174 174
 	{NULL,"http://key.com","=====key.com",2},
175
+	{NULL," http://key.com","=====key.com",2},
175 176
 	{NULL,"http://key.com@fake.example.com","key.com",0},
177
+	{NULL," http://key.com@fake.example.com","key.com",0},
178
+	{NULL," http://key.com@fake.example.com ","key.com",0},
176 179
 	/* entry taken from .wdb with a / appended */
177 180
 	{".+\\.ebayrtm\\.com([/?].*)?:.+\\.ebay\\.(de|com|co\\.uk)([/?].*)?/",
178 181
 		"http://srx.main.ebayrtm.com",