mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
Check that memory functions return non-NULL or return error.
This commit is contained in:
parent
8e09a389c4
commit
fd775454ca
@ -230,8 +230,6 @@ CURLcode Curl_output_digest(struct connectdata *conn,
|
|||||||
}
|
}
|
||||||
authp->done = TRUE;
|
authp->done = TRUE;
|
||||||
|
|
||||||
ha1 = (unsigned char *)malloc(33); /* 32 digits and 1 zero byte */
|
|
||||||
|
|
||||||
if(!d->nc)
|
if(!d->nc)
|
||||||
d->nc = 1;
|
d->nc = 1;
|
||||||
|
|
||||||
@ -239,8 +237,10 @@ CURLcode Curl_output_digest(struct connectdata *conn,
|
|||||||
/* Generate a cnonce */
|
/* Generate a cnonce */
|
||||||
now = Curl_tvnow();
|
now = Curl_tvnow();
|
||||||
snprintf(cnoncebuf, sizeof(cnoncebuf), "%06ld", now.tv_sec);
|
snprintf(cnoncebuf, sizeof(cnoncebuf), "%06ld", now.tv_sec);
|
||||||
Curl_base64_encode(cnoncebuf, strlen(cnoncebuf), &cnonce);
|
if(Curl_base64_encode(cnoncebuf, strlen(cnoncebuf), &cnonce))
|
||||||
d->cnonce = cnonce;
|
d->cnonce = cnonce;
|
||||||
|
else
|
||||||
|
return CURLE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -256,15 +256,23 @@ CURLcode Curl_output_digest(struct connectdata *conn,
|
|||||||
|
|
||||||
md5this = (unsigned char *)
|
md5this = (unsigned char *)
|
||||||
aprintf("%s:%s:%s", conn->user, d->realm, conn->passwd);
|
aprintf("%s:%s:%s", conn->user, d->realm, conn->passwd);
|
||||||
|
if(!md5this)
|
||||||
|
return CURLE_OUT_OF_MEMORY;
|
||||||
Curl_md5it(md5buf, md5this);
|
Curl_md5it(md5buf, md5this);
|
||||||
free(md5this); /* free this again */
|
free(md5this); /* free this again */
|
||||||
|
|
||||||
|
ha1 = (unsigned char *)malloc(33); /* 32 digits and 1 zero byte */
|
||||||
|
if(!ha1)
|
||||||
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
md5_to_ascii(md5buf, ha1);
|
md5_to_ascii(md5buf, ha1);
|
||||||
|
|
||||||
if(d->algo == CURLDIGESTALGO_MD5SESS) {
|
if(d->algo == CURLDIGESTALGO_MD5SESS) {
|
||||||
/* nonce and cnonce are OUTSIDE the hash */
|
/* nonce and cnonce are OUTSIDE the hash */
|
||||||
tmp = aprintf("%s:%s:%s", ha1, d->nonce, d->cnonce);
|
tmp = aprintf("%s:%s:%s", ha1, d->nonce, d->cnonce);
|
||||||
|
|
||||||
free(ha1);
|
free(ha1);
|
||||||
|
if(!tmp)
|
||||||
|
return CURLE_OUT_OF_MEMORY;
|
||||||
ha1 = (unsigned char *)tmp;
|
ha1 = (unsigned char *)tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,6 +290,11 @@ CURLcode Curl_output_digest(struct connectdata *conn,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
md5this = (unsigned char *)aprintf("%s:%s", request, uripath);
|
md5this = (unsigned char *)aprintf("%s:%s", request, uripath);
|
||||||
|
if(!md5this) {
|
||||||
|
free(ha1);
|
||||||
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
if (d->qop && strequal(d->qop, "auth-int")) {
|
if (d->qop && strequal(d->qop, "auth-int")) {
|
||||||
/* We don't support auth-int at the moment. I can't see a easy way to get
|
/* We don't support auth-int at the moment. I can't see a easy way to get
|
||||||
entity-body here */
|
entity-body here */
|
||||||
@ -307,6 +320,8 @@ CURLcode Curl_output_digest(struct connectdata *conn,
|
|||||||
ha2);
|
ha2);
|
||||||
}
|
}
|
||||||
free(ha1);
|
free(ha1);
|
||||||
|
if(!md5this)
|
||||||
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
Curl_md5it(md5buf, md5this);
|
Curl_md5it(md5buf, md5this);
|
||||||
free(md5this); /* free this again */
|
free(md5this); /* free this again */
|
||||||
@ -361,27 +376,34 @@ CURLcode Curl_output_digest(struct connectdata *conn,
|
|||||||
uripath, /* this is the PATH part of the URL */
|
uripath, /* this is the PATH part of the URL */
|
||||||
request_digest);
|
request_digest);
|
||||||
}
|
}
|
||||||
|
if(!*userp)
|
||||||
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
/* Add optional fields */
|
/* Add optional fields */
|
||||||
if(d->opaque) {
|
if(d->opaque) {
|
||||||
/* append opaque */
|
/* append opaque */
|
||||||
tmp = aprintf(", opaque=\"%s\"", d->opaque);
|
tmp = aprintf("%s, opaque=\"%s\"", *userp, d->opaque);
|
||||||
*userp = (char*) realloc(*userp, strlen(*userp) + strlen(tmp) + 1);
|
if(!tmp)
|
||||||
strcat(*userp, tmp);
|
return CURLE_OUT_OF_MEMORY;
|
||||||
free(tmp);
|
free(*userp);
|
||||||
|
*userp = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(d->algorithm) {
|
if(d->algorithm) {
|
||||||
/* append algorithm */
|
/* append algorithm */
|
||||||
tmp = aprintf(", algorithm=\"%s\"", d->algorithm);
|
tmp = aprintf("%s, algorithm=\"%s\"", *userp, d->algorithm);
|
||||||
*userp = (char*) realloc(*userp, strlen(*userp) + strlen(tmp) + 1);
|
if(!tmp)
|
||||||
strcat(conn->allocptr.userpwd, tmp);
|
return CURLE_OUT_OF_MEMORY;
|
||||||
free(tmp);
|
free(*userp);
|
||||||
|
*userp = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* append CRLF to the userpwd header */
|
/* append CRLF to the userpwd header */
|
||||||
*userp = (char*) realloc(*userp, strlen(*userp) + 3 + 1);
|
tmp = (char*) realloc(*userp, strlen(*userp) + 3 + 1);
|
||||||
strcat(*userp, "\r\n");
|
if(!tmp)
|
||||||
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
strcat(tmp, "\r\n");
|
||||||
|
*userp = tmp;
|
||||||
|
|
||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user