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:
Daniel Stenberg 2002-10-28 21:52:00 +00:00
parent 8f52b731f4
commit 01387f42c5
5 changed files with 31 additions and 28 deletions

View File

@ -519,7 +519,7 @@ struct CookieInfo *Curl_cookie_init(char *file,
char *lineptr;
bool headerline;
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! */
lineptr=&line[11];
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
requirement */
if(!co->path ||
strnequal(path, co->path, strlen(co->path))) {
if(!co->path ||
checkprefix(co->path, path) ) {
/* and now, we know this is a match and we should create an
entry for the return-linked-list */

View File

@ -1218,7 +1218,7 @@ CURLcode Curl_getFormData(struct FormData **finalform,
*/
if(file->contenttype &&
!strnequal("text/", file->contenttype, 5)) {
!checkprefix("text/", file->contenttype)) {
/* this is not a text content, mention our binary encoding */
size += AddFormData(&form, "\r\nContent-Transfer-Encoding: binary", 0);
}

View File

@ -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 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
#define strlcat(x,y,z) Curl_strlcat(x,y,z)
size_t Curl_strlcat(char *dst, const char *src, size_t siz);

View File

@ -291,7 +291,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
k->hbuflen += nread;
if (!k->headerline && (k->hbuflen>5)) {
/* 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 */
k->header = FALSE;
k->badheader = HEADER_ALLBAD;
@ -345,7 +345,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
if(!k->headerline) {
/* the first read header */
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 */
k->header = FALSE;
k->badheader = HEADER_PARTHEADER;
@ -521,13 +521,13 @@ CURLcode Curl_readwrite(struct connectdata *conn,
}
/* 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)) {
conn->size = k->contentlength;
Curl_pgrsSetDownloadSize(data, k->contentlength);
}
/* 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 *end;
int len;
@ -597,7 +597,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
/* init our chunky engine */
Curl_httpchunk_init(conn);
}
else if (strnequal("Content-Encoding:", k->p, 17) &&
else if (checkprefix("Content-Encoding:", k->p) &&
data->set.encoding) {
/*
* Process Content-Encoding. Look for the values: identity, gzip,
@ -614,18 +614,18 @@ CURLcode Curl_readwrite(struct connectdata *conn,
start++);
/* Record the content-encoding for later use. 08/27/02 jhrg */
if (strnequal("identity", start, 8))
if (checkprefix("identity", start))
k->content_encoding = IDENTITY;
else if (strnequal("deflate", start, 7))
else if (checkprefix("deflate", start))
k->content_encoding = DEFLATE;
else if (strnequal("gzip", start, 4)
|| strnequal("x-gzip", start, 6))
else if (checkprefix("gzip", start)
|| checkprefix("x-gzip", start))
k->content_encoding = GZIP;
else if (strnequal("compress", start, 8)
|| strnequal("x-compress", start, 10))
else if (checkprefix("compress", start)
|| checkprefix("x-compress", start))
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) ||
sscanf (k->p+14, " bytes: %d-", &k->offset)) {
/* This second format was added August 1st 2000 by Igor
@ -638,11 +638,10 @@ CURLcode Curl_readwrite(struct connectdata *conn,
}
}
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);
}
else if(strnequal("Last-Modified:", k->p,
strlen("Last-Modified:")) &&
else if(checkprefix("Last-Modified:", k->p) &&
(data->set.timecondition || data->set.get_filetime) ) {
time_t secs=time(NULL);
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) &&
(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 */
char *ptr;
char *start=k->p;

View File

@ -1848,22 +1848,22 @@ static CURLcode CreateConnection(struct SessionHandle *data,
/* Note: if you add a new protocol, please update the list in
* lib/version.c too! */
if(strnequal(conn->gname, "FTP", 3)) {
if(checkprefix("FTP", conn->gname)) {
strcpy(conn->protostr, "ftp");
}
else if(strnequal(conn->gname, "GOPHER", 6))
else if(checkprefix("GOPHER", conn->gname))
strcpy(conn->protostr, "gopher");
#ifdef USE_SSLEAY
else if(strnequal(conn->gname, "HTTPS", 5))
else if(checkprefix("HTTPS", conn->gname))
strcpy(conn->protostr, "https");
else if(strnequal(conn->gname, "FTPS", 4))
else if(checkprefix("FTPS", conn->gname))
strcpy(conn->protostr, "ftps");
#endif /* USE_SSLEAY */
else if(strnequal(conn->gname, "TELNET", 6))
else if(checkprefix("TELNET", conn->gname))
strcpy(conn->protostr, "telnet");
else if (strnequal(conn->gname, "DICT", sizeof("DICT")-1))
else if (checkprefix("DICT", conn->gname))
strcpy(conn->protostr, "DICT");
else if (strnequal(conn->gname, "LDAP", sizeof("LDAP")-1))
else if (checkprefix("LDAP", conn->gname))
strcpy(conn->protostr, "LDAP");
else {
strcpy(conn->protostr, "http");
@ -1966,7 +1966,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
if(strlen(nope) <= namelen) {
char *checkn=
conn->name + namelen - strlen(nope);
if(strnequal(nope, checkn, strlen(nope))) {
if(checkprefix(nope, checkn)) {
/* no proxy for this host! */
break;
}