mirror of
https://github.com/curl/curl.git
synced 2026-08-26 00:43:52 +03:00
base64: fix Curl_base64_encode and Curl_base64_decode interfaces
Previous interfaces for these libcurl internal functions did not allow to tell apart a legitimate zero size result from an error condition. These functions now return a CURLcode indicating function success or otherwise specific error. Output size is returned using a pointer argument. All usage of these two functions, and others closely related, has been adapted to the new interfaces. Relative error and OOM handling adapted or added where missing. Unit test 1302 also adapted.
This commit is contained in:
parent
cce6508242
commit
fd00b382b2
18 changed files with 380 additions and 225 deletions
36
lib/http.c
36
lib/http.c
|
|
@ -231,11 +231,13 @@ static char *copy_header_value(const char *h)
|
|||
*/
|
||||
static CURLcode http_output_basic(struct connectdata *conn, bool proxy)
|
||||
{
|
||||
char *authorization;
|
||||
struct SessionHandle *data=conn->data;
|
||||
size_t size = 0;
|
||||
char *authorization = NULL;
|
||||
struct SessionHandle *data = conn->data;
|
||||
char **userp;
|
||||
const char *user;
|
||||
const char *pwd;
|
||||
CURLcode error;
|
||||
|
||||
if(proxy) {
|
||||
userp = &conn->allocptr.proxyuserpwd;
|
||||
|
|
@ -249,20 +251,24 @@ static CURLcode http_output_basic(struct connectdata *conn, bool proxy)
|
|||
}
|
||||
|
||||
snprintf(data->state.buffer, sizeof(data->state.buffer), "%s:%s", user, pwd);
|
||||
if(Curl_base64_encode(data, data->state.buffer,
|
||||
strlen(data->state.buffer),
|
||||
&authorization) > 0) {
|
||||
if(*userp)
|
||||
free(*userp);
|
||||
*userp = aprintf( "%sAuthorization: Basic %s\r\n",
|
||||
proxy?"Proxy-":"",
|
||||
authorization);
|
||||
free(authorization);
|
||||
if(!*userp)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
else
|
||||
|
||||
error = Curl_base64_encode(data,
|
||||
data->state.buffer, strlen(data->state.buffer),
|
||||
&authorization, &size);
|
||||
if(error)
|
||||
return error;
|
||||
|
||||
if(!authorization)
|
||||
return CURLE_REMOTE_ACCESS_DENIED;
|
||||
|
||||
Curl_safefree(*userp);
|
||||
*userp = aprintf("%sAuthorization: Basic %s\r\n",
|
||||
proxy?"Proxy-":"",
|
||||
authorization);
|
||||
free(authorization);
|
||||
if(!*userp)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue