mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
kromJx@crosswinds.net's fix that now uses checkprefix() instead of
strnequal() when the third argument was strlen(first argument) anyway. This makes it less prone to errors. (Slightly edited by me)
This commit is contained in:
parent
8f52b731f4
commit
01387f42c5
@ -519,7 +519,7 @@ struct CookieInfo *Curl_cookie_init(char *file,
|
|||||||
char *lineptr;
|
char *lineptr;
|
||||||
bool headerline;
|
bool headerline;
|
||||||
while(fgets(line, MAX_COOKIE_LINE, fp)) {
|
while(fgets(line, MAX_COOKIE_LINE, fp)) {
|
||||||
if(strnequal("Set-Cookie:", line, 11)) {
|
if(checkprefix("Set-Cookie:", line)) {
|
||||||
/* This is a cookie line, get it! */
|
/* This is a cookie line, get it! */
|
||||||
lineptr=&line[11];
|
lineptr=&line[11];
|
||||||
headerline=TRUE;
|
headerline=TRUE;
|
||||||
@ -587,8 +587,8 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
|
|||||||
|
|
||||||
/* now check the left part of the path with the cookies path
|
/* now check the left part of the path with the cookies path
|
||||||
requirement */
|
requirement */
|
||||||
if(!co->path ||
|
if(!co->path ||
|
||||||
strnequal(path, co->path, strlen(co->path))) {
|
checkprefix(co->path, path) ) {
|
||||||
|
|
||||||
/* and now, we know this is a match and we should create an
|
/* and now, we know this is a match and we should create an
|
||||||
entry for the return-linked-list */
|
entry for the return-linked-list */
|
||||||
|
@ -1218,7 +1218,7 @@ CURLcode Curl_getFormData(struct FormData **finalform,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if(file->contenttype &&
|
if(file->contenttype &&
|
||||||
!strnequal("text/", file->contenttype, 5)) {
|
!checkprefix("text/", file->contenttype)) {
|
||||||
/* this is not a text content, mention our binary encoding */
|
/* this is not a text content, mention our binary encoding */
|
||||||
size += AddFormData(&form, "\r\nContent-Transfer-Encoding: binary", 0);
|
size += AddFormData(&form, "\r\nContent-Transfer-Encoding: binary", 0);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,10 @@ int curl_strnequal(const char *first, const char *second, size_t max);
|
|||||||
#define strequal(a,b) curl_strequal(a,b)
|
#define strequal(a,b) curl_strequal(a,b)
|
||||||
#define strnequal(a,b,c) curl_strnequal(a,b,c)
|
#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))
|
||||||
|
|
||||||
#ifndef HAVE_STRLCAT
|
#ifndef HAVE_STRLCAT
|
||||||
#define strlcat(x,y,z) Curl_strlcat(x,y,z)
|
#define strlcat(x,y,z) Curl_strlcat(x,y,z)
|
||||||
size_t Curl_strlcat(char *dst, const char *src, size_t siz);
|
size_t Curl_strlcat(char *dst, const char *src, size_t siz);
|
||||||
|
@ -291,7 +291,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
|||||||
k->hbuflen += nread;
|
k->hbuflen += nread;
|
||||||
if (!k->headerline && (k->hbuflen>5)) {
|
if (!k->headerline && (k->hbuflen>5)) {
|
||||||
/* make a first check that this looks like a HTTP header */
|
/* make a first check that this looks like a HTTP header */
|
||||||
if(!strnequal(data->state.headerbuff, "HTTP/", 5)) {
|
if(!checkprefix(data->state.headerbuff, "HTTP/")) {
|
||||||
/* this is not the beginning of a HTTP first header line */
|
/* this is not the beginning of a HTTP first header line */
|
||||||
k->header = FALSE;
|
k->header = FALSE;
|
||||||
k->badheader = HEADER_ALLBAD;
|
k->badheader = HEADER_ALLBAD;
|
||||||
@ -345,7 +345,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
|||||||
if(!k->headerline) {
|
if(!k->headerline) {
|
||||||
/* the first read header */
|
/* the first read header */
|
||||||
if((k->hbuflen>5) &&
|
if((k->hbuflen>5) &&
|
||||||
!strnequal(data->state.headerbuff, "HTTP/", 5)) {
|
!checkprefix(data->state.headerbuff, "HTTP/")) {
|
||||||
/* this is not the beginning of a HTTP first header line */
|
/* this is not the beginning of a HTTP first header line */
|
||||||
k->header = FALSE;
|
k->header = FALSE;
|
||||||
k->badheader = HEADER_PARTHEADER;
|
k->badheader = HEADER_PARTHEADER;
|
||||||
@ -521,13 +521,13 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check for Content-Length: header lines to get size */
|
/* check for Content-Length: header lines to get size */
|
||||||
if (strnequal("Content-Length:", k->p, 15) &&
|
if (checkprefix("Content-Length:", k->p) &&
|
||||||
sscanf (k->p+15, " %ld", &k->contentlength)) {
|
sscanf (k->p+15, " %ld", &k->contentlength)) {
|
||||||
conn->size = k->contentlength;
|
conn->size = k->contentlength;
|
||||||
Curl_pgrsSetDownloadSize(data, k->contentlength);
|
Curl_pgrsSetDownloadSize(data, k->contentlength);
|
||||||
}
|
}
|
||||||
/* check for Content-Type: header lines to get the mime-type */
|
/* check for Content-Type: header lines to get the mime-type */
|
||||||
else if (strnequal("Content-Type:", k->p, 13)) {
|
else if (checkprefix("Content-Type:", k->p)) {
|
||||||
char *start;
|
char *start;
|
||||||
char *end;
|
char *end;
|
||||||
int len;
|
int len;
|
||||||
@ -597,7 +597,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
|||||||
/* init our chunky engine */
|
/* init our chunky engine */
|
||||||
Curl_httpchunk_init(conn);
|
Curl_httpchunk_init(conn);
|
||||||
}
|
}
|
||||||
else if (strnequal("Content-Encoding:", k->p, 17) &&
|
else if (checkprefix("Content-Encoding:", k->p) &&
|
||||||
data->set.encoding) {
|
data->set.encoding) {
|
||||||
/*
|
/*
|
||||||
* Process Content-Encoding. Look for the values: identity, gzip,
|
* Process Content-Encoding. Look for the values: identity, gzip,
|
||||||
@ -614,18 +614,18 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
|||||||
start++);
|
start++);
|
||||||
|
|
||||||
/* Record the content-encoding for later use. 08/27/02 jhrg */
|
/* Record the content-encoding for later use. 08/27/02 jhrg */
|
||||||
if (strnequal("identity", start, 8))
|
if (checkprefix("identity", start))
|
||||||
k->content_encoding = IDENTITY;
|
k->content_encoding = IDENTITY;
|
||||||
else if (strnequal("deflate", start, 7))
|
else if (checkprefix("deflate", start))
|
||||||
k->content_encoding = DEFLATE;
|
k->content_encoding = DEFLATE;
|
||||||
else if (strnequal("gzip", start, 4)
|
else if (checkprefix("gzip", start)
|
||||||
|| strnequal("x-gzip", start, 6))
|
|| checkprefix("x-gzip", start))
|
||||||
k->content_encoding = GZIP;
|
k->content_encoding = GZIP;
|
||||||
else if (strnequal("compress", start, 8)
|
else if (checkprefix("compress", start)
|
||||||
|| strnequal("x-compress", start, 10))
|
|| checkprefix("x-compress", start))
|
||||||
k->content_encoding = COMPRESS;
|
k->content_encoding = COMPRESS;
|
||||||
}
|
}
|
||||||
else if (strnequal("Content-Range:", k->p, 14)) {
|
else if (checkprefix("Content-Range:", k->p)) {
|
||||||
if (sscanf (k->p+14, " bytes %d-", &k->offset) ||
|
if (sscanf (k->p+14, " bytes %d-", &k->offset) ||
|
||||||
sscanf (k->p+14, " bytes: %d-", &k->offset)) {
|
sscanf (k->p+14, " bytes: %d-", &k->offset)) {
|
||||||
/* This second format was added August 1st 2000 by Igor
|
/* This second format was added August 1st 2000 by Igor
|
||||||
@ -638,11 +638,10 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(data->cookies &&
|
else if(data->cookies &&
|
||||||
strnequal("Set-Cookie:", k->p, 11)) {
|
checkprefix("Set-Cookie:", k->p)) {
|
||||||
Curl_cookie_add(data->cookies, TRUE, k->p+11, conn->name);
|
Curl_cookie_add(data->cookies, TRUE, k->p+11, conn->name);
|
||||||
}
|
}
|
||||||
else if(strnequal("Last-Modified:", k->p,
|
else if(checkprefix("Last-Modified:", k->p) &&
|
||||||
strlen("Last-Modified:")) &&
|
|
||||||
(data->set.timecondition || data->set.get_filetime) ) {
|
(data->set.timecondition || data->set.get_filetime) ) {
|
||||||
time_t secs=time(NULL);
|
time_t secs=time(NULL);
|
||||||
k->timeofdoc = curl_getdate(k->p+strlen("Last-Modified:"),
|
k->timeofdoc = curl_getdate(k->p+strlen("Last-Modified:"),
|
||||||
@ -652,7 +651,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
|||||||
}
|
}
|
||||||
else if ((k->httpcode >= 300 && k->httpcode < 400) &&
|
else if ((k->httpcode >= 300 && k->httpcode < 400) &&
|
||||||
(data->set.http_follow_location) &&
|
(data->set.http_follow_location) &&
|
||||||
strnequal("Location:", k->p, 9)) {
|
checkprefix("Location:", k->p)) {
|
||||||
/* this is the URL that the server advices us to get instead */
|
/* this is the URL that the server advices us to get instead */
|
||||||
char *ptr;
|
char *ptr;
|
||||||
char *start=k->p;
|
char *start=k->p;
|
||||||
|
16
lib/url.c
16
lib/url.c
@ -1848,22 +1848,22 @@ static CURLcode CreateConnection(struct SessionHandle *data,
|
|||||||
/* Note: if you add a new protocol, please update the list in
|
/* Note: if you add a new protocol, please update the list in
|
||||||
* lib/version.c too! */
|
* lib/version.c too! */
|
||||||
|
|
||||||
if(strnequal(conn->gname, "FTP", 3)) {
|
if(checkprefix("FTP", conn->gname)) {
|
||||||
strcpy(conn->protostr, "ftp");
|
strcpy(conn->protostr, "ftp");
|
||||||
}
|
}
|
||||||
else if(strnequal(conn->gname, "GOPHER", 6))
|
else if(checkprefix("GOPHER", conn->gname))
|
||||||
strcpy(conn->protostr, "gopher");
|
strcpy(conn->protostr, "gopher");
|
||||||
#ifdef USE_SSLEAY
|
#ifdef USE_SSLEAY
|
||||||
else if(strnequal(conn->gname, "HTTPS", 5))
|
else if(checkprefix("HTTPS", conn->gname))
|
||||||
strcpy(conn->protostr, "https");
|
strcpy(conn->protostr, "https");
|
||||||
else if(strnequal(conn->gname, "FTPS", 4))
|
else if(checkprefix("FTPS", conn->gname))
|
||||||
strcpy(conn->protostr, "ftps");
|
strcpy(conn->protostr, "ftps");
|
||||||
#endif /* USE_SSLEAY */
|
#endif /* USE_SSLEAY */
|
||||||
else if(strnequal(conn->gname, "TELNET", 6))
|
else if(checkprefix("TELNET", conn->gname))
|
||||||
strcpy(conn->protostr, "telnet");
|
strcpy(conn->protostr, "telnet");
|
||||||
else if (strnequal(conn->gname, "DICT", sizeof("DICT")-1))
|
else if (checkprefix("DICT", conn->gname))
|
||||||
strcpy(conn->protostr, "DICT");
|
strcpy(conn->protostr, "DICT");
|
||||||
else if (strnequal(conn->gname, "LDAP", sizeof("LDAP")-1))
|
else if (checkprefix("LDAP", conn->gname))
|
||||||
strcpy(conn->protostr, "LDAP");
|
strcpy(conn->protostr, "LDAP");
|
||||||
else {
|
else {
|
||||||
strcpy(conn->protostr, "http");
|
strcpy(conn->protostr, "http");
|
||||||
@ -1966,7 +1966,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
|
|||||||
if(strlen(nope) <= namelen) {
|
if(strlen(nope) <= namelen) {
|
||||||
char *checkn=
|
char *checkn=
|
||||||
conn->name + namelen - strlen(nope);
|
conn->name + namelen - strlen(nope);
|
||||||
if(strnequal(nope, checkn, strlen(nope))) {
|
if(checkprefix(nope, checkn)) {
|
||||||
/* no proxy for this host! */
|
/* no proxy for this host! */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user