diff options
author | Yang Tse <yangsita@gmail.com> | 2011-08-24 08:07:36 +0200 |
---|---|---|
committer | Yang Tse <yangsita@gmail.com> | 2011-08-24 08:10:30 +0200 |
commit | fd00b382b2d33ef90c6f5c840a32b66c8ceb1662 (patch) | |
tree | e95c73f96e5b4e67059326823e68ce78fc6f300b /lib/http.c | |
parent | cce6508242ab73cca896788ad9f968b89e5f9f3a (diff) |
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.
Diffstat (limited to 'lib/http.c')
-rw-r--r-- | lib/http.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/http.c b/lib/http.c index 4952ddd64..edf3e163f 100644 --- a/lib/http.c +++ b/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; } |