diff options
-rw-r--r-- | lib/cookie.c | 2 | ||||
-rw-r--r-- | lib/dict.c | 12 | ||||
-rw-r--r-- | lib/ftp.c | 2 | ||||
-rw-r--r-- | lib/http.c | 11 | ||||
-rw-r--r-- | lib/security.c | 2 | ||||
-rw-r--r-- | lib/ssh.c | 2 | ||||
-rw-r--r-- | lib/sslgen.c | 4 | ||||
-rw-r--r-- | lib/strequal.c | 16 | ||||
-rw-r--r-- | lib/strequal.h | 9 | ||||
-rw-r--r-- | lib/url.c | 2 |
10 files changed, 38 insertions, 24 deletions
diff --git a/lib/cookie.c b/lib/cookie.c index f2de8eaf9..fed4a44f6 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -131,7 +131,7 @@ static bool tailmatch(const char *little, const char *bigone) if(littlelen > biglen) return FALSE; - return (bool)strequal(little, bigone+biglen-littlelen); + return (bool)Curl_raw_equal(little, bigone+biglen-littlelen); } /* diff --git a/lib/dict.c b/lib/dict.c index b1f5b6810..f9ce50efc 100644 --- a/lib/dict.c +++ b/lib/dict.c @@ -163,9 +163,9 @@ static CURLcode dict_do(struct connectdata *conn, bool *done) /* AUTH is missing */ } - if(strnequal(path, DICT_MATCH, sizeof(DICT_MATCH)-1) || - strnequal(path, DICT_MATCH2, sizeof(DICT_MATCH2)-1) || - strnequal(path, DICT_MATCH3, sizeof(DICT_MATCH3)-1)) { + if(Curl_raw_nequal(path, DICT_MATCH, sizeof(DICT_MATCH)-1) || + Curl_raw_nequal(path, DICT_MATCH2, sizeof(DICT_MATCH2)-1) || + Curl_raw_nequal(path, DICT_MATCH3, sizeof(DICT_MATCH3)-1)) { word = strchr(path, ':'); if(word) { @@ -222,9 +222,9 @@ static CURLcode dict_do(struct connectdata *conn, bool *done) if(result) return result; } - else if(strnequal(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) || - strnequal(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) || - strnequal(path, DICT_DEFINE3, sizeof(DICT_DEFINE3)-1)) { + else if(Curl_raw_nequal(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) || + Curl_raw_nequal(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) || + Curl_raw_nequal(path, DICT_DEFINE3, sizeof(DICT_DEFINE3)-1)) { word = strchr(path, ':'); if(word) { @@ -4019,7 +4019,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn) dlen -= ftpc->file?strlen(ftpc->file):0; if((dlen == (int)strlen(ftpc->prevpath)) && - curl_strnequal(path, ftpc->prevpath, dlen)) { + strnequal(path, ftpc->prevpath, dlen)) { infof(data, "Request has same path as previous transfer\n"); ftpc->cwddone = TRUE; } diff --git a/lib/http.c b/lib/http.c index b1b70ce4e..503ceb0c1 100644 --- a/lib/http.c +++ b/lib/http.c @@ -173,7 +173,7 @@ static char *checkheaders(struct SessionHandle *data, const char *thisheader) size_t thislen = strlen(thisheader); for(head = data->set.headers; head; head=head->next) { - if(strnequal(head->data, thisheader, thislen)) + if(Curl_raw_nequal(head->data, thisheader, thislen)) return head->data; } return NULL; @@ -1246,7 +1246,7 @@ Curl_compareheader(const char *headerline, /* line to check */ const char *start; const char *end; - if(!strnequal(headerline, header, hlen)) + if(!Curl_raw_nequal(headerline, header, hlen)) return FALSE; /* doesn't start with header */ /* pass the header */ @@ -1272,7 +1272,7 @@ Curl_compareheader(const char *headerline, /* line to check */ /* find the content string in the rest of the line */ for(;len>=clen;len--, start++) { - if(strnequal(start, content, clen)) + if(Curl_raw_nequal(start, content, clen)) return TRUE; /* match! */ } @@ -2026,12 +2026,11 @@ static CURLcode add_custom_headers(struct connectdata *conn, if(conn->allocptr.host && /* a Host: header was sent already, don't pass on any custom Host: header as that will produce *two* in the same request! */ - curl_strnequal("Host:", headers->data, 5)) + checkprefix("Host:", headers->data)) ; else if(conn->data->set.httpreq == HTTPREQ_POST_FORM && /* this header (extended by formdata.c) is sent later */ - curl_strnequal("Content-Type:", headers->data, - strlen("Content-Type:"))) + checkprefix("Content-Type:", headers->data)) ; else { CURLcode result = add_bufferf(req_buffer, "%s\r\n", headers->data); diff --git a/lib/security.c b/lib/security.c index bec751045..01143938a 100644 --- a/lib/security.c +++ b/lib/security.c @@ -85,7 +85,7 @@ name_to_level(const char *name) { int i; for(i = 0; i < (int)sizeof(level_names)/(int)sizeof(level_names[0]); i++) - if(curl_strnequal(level_names[i].name, name, strlen(name))) + if(checkprefix(name, level_names[i].name)) return level_names[i].level; return (enum protection_level)-1; } @@ -822,7 +822,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn) /* * Support some of the "FTP" commands */ - if(curl_strnequal(sshc->quote_item->data, "PWD", 3)) { + if(curl_strequal("pwd", sshc->quote_item->data)) { /* output debug output if that is requested */ if(data->set.verbose) { char tmp[PATH_MAX+1]; diff --git a/lib/sslgen.c b/lib/sslgen.c index eee46b912..1bfeda713 100644 --- a/lib/sslgen.c +++ b/lib/sslgen.c @@ -64,8 +64,6 @@ /* The last #include file should be: */ #include "memdebug.h" -static bool safe_strequal(char* str1, char* str2); - static bool safe_strequal(char* str1, char* str2) { if(str1 && str2) @@ -228,7 +226,7 @@ int Curl_ssl_getsessionid(struct connectdata *conn, if(!check->sessionid) /* not session ID means blank entry */ continue; - if(curl_strequal(conn->host.name, check->name) && + if(Curl_raw_equal(conn->host.name, check->name) && (conn->remote_port == check->remote_port) && Curl_ssl_config_matches(&conn->ssl_config, &check->ssl_config)) { /* yes, we have a session ID! */ diff --git a/lib/strequal.c b/lib/strequal.c index 5065b3871..3d00aa213 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -161,6 +161,22 @@ int Curl_raw_equal(const char *first, const char *second) return (my_toupper(*first) == my_toupper(*second)); } +int Curl_raw_nequal(const char *first, const char *second, size_t max) +{ + while(*first && *second && max) { + if(my_toupper(*first) != my_toupper(*second)) { + break; + } + max--; + first++; + second++; + } + if(0 == max) + return 1; /* they are equal this far */ + + return my_toupper(*first) == my_toupper(*second); +} + #ifndef HAVE_STRLCAT /* * The strlcat() function appends the NUL-terminated string src to the end diff --git a/lib/strequal.h b/lib/strequal.h index 778b23cd9..eac400202 100644 --- a/lib/strequal.h +++ b/lib/strequal.h @@ -28,10 +28,6 @@ #define strequal(a,b) curl_strequal(a,b) #define strnequal(a,b,c) curl_strnequal(a,b,c) -/* checkprefix() is a shorter version of the above, used when the first - argument is zero-byte terminated */ -#define checkprefix(a,b) strnequal(a,b,strlen(a)) - /* * Curl_raw_equal() is for doing "raw" case insensitive strings. This is meant * to be locale independent and only compare strings we know are safe for @@ -40,6 +36,11 @@ * The function is capable of comparing a-z case insensitively even for non-ascii. */ int Curl_raw_equal(const char *first, const char *second); +int Curl_raw_nequal(const char *first, const char *second, size_t max); + +/* checkprefix() is a shorter version of the above, used when the first + argument is zero-byte terminated */ +#define checkprefix(a,b) Curl_raw_nequal(a,b,strlen(a)) #ifndef HAVE_STRLCAT #define strlcat(x,y,z) Curl_strlcat(x,y,z) @@ -3337,7 +3337,7 @@ static char *detect_proxy(struct connectdata *conn) if(!no_proxy) no_proxy=curl_getenv("NO_PROXY"); - if(!no_proxy || !strequal("*", no_proxy)) { + if(!no_proxy || !Curl_raw_equal("*", no_proxy)) { /* NO_PROXY wasn't specified or it wasn't just an asterisk */ char *nope; |