diff --git a/src/protocol/uri.c b/src/protocol/uri.c index 897e4b8e0..ad10ec8d7 100644 --- a/src/protocol/uri.c +++ b/src/protocol/uri.c @@ -115,28 +115,31 @@ end_with_known_tld(unsigned char *s, int slen) return -1; } +/* XXX: this function writes to @name. */ static int check_whether_file_exists(unsigned char *name) { /* Check POST_CHAR etc ... */ static const unsigned char chars[] = POST_CHAR_S "#?"; int i; + int namelen = strlen(name); if (file_exists(name)) - return strlen(name); + return namelen; for (i = 0; i < sizeof(chars) - 1; i++) { - unsigned char *pos = strchr(name, chars[i]); - int namelen = -1; - + unsigned char *pos = memchr(name, chars[i], namelen); + int exists; + if (!pos) continue; *pos = 0; - if (file_exists(name)) - namelen = strlen(name); + exists = file_exists(name); *pos = chars[i]; - - if (namelen >= 0) return namelen; + + if (exists) { + return pos - name; + } } return -1;