diff mbox series

[OpenWrt-Devel,2/6] uclient-http: basic auth: Handle memory allocation failure

Message ID 20180218033640.17715-3-tobleminer@gmail.com
State Changes Requested
Delegated to: John Crispin
Headers show
Series uclient: Handle memory allocation failures | expand

Commit Message

Tobias Schramm Feb. 18, 2018, 3:36 a.m. UTC
Signed-off-by: Tobias Schramm <tobleminer@gmail.com>
---
 uclient-http.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

John Crispin Feb. 18, 2018, 10:17 a.m. UTC | #1
On 18/02/18 04:36, Tobias Schramm wrote:
> Signed-off-by: Tobias Schramm <tobleminer@gmail.com>

looks good, but the caller should honour the return value aswell

     John

> ---
>   uclient-http.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/uclient-http.c b/uclient-http.c
> index ef8de98..36e051b 100644
> --- a/uclient-http.c
> +++ b/uclient-http.c
> @@ -299,7 +299,7 @@ static bool uclient_request_supports_body(enum request_type req_type)
>   	}
>   }
>   
> -static void
> +static int
>   uclient_http_add_auth_basic(struct uclient_http *uh)
>   {
>   	struct uclient_url *url = uh->uc.url;
> @@ -307,11 +307,16 @@ uclient_http_add_auth_basic(struct uclient_http *uh)
>   	char *auth_buf;
>   
>   	if (auth_len > 512)
> -		return;
> +		return -EINVAL;
>   
>   	auth_buf = alloca(base64_len(auth_len) + 1);
> +	if(!auth_buf)
> +		return -ENOMEM;
> +
>   	base64_encode(url->auth, auth_len, auth_buf);
>   	ustream_printf(uh->us, "Authorization: Basic %s\r\n", auth_buf);
> +
> +	return 0;
>   }
>   
>   static char *digest_unquote_sep(char **str)
diff mbox series

Patch

diff --git a/uclient-http.c b/uclient-http.c
index ef8de98..36e051b 100644
--- a/uclient-http.c
+++ b/uclient-http.c
@@ -299,7 +299,7 @@  static bool uclient_request_supports_body(enum request_type req_type)
 	}
 }
 
-static void
+static int
 uclient_http_add_auth_basic(struct uclient_http *uh)
 {
 	struct uclient_url *url = uh->uc.url;
@@ -307,11 +307,16 @@  uclient_http_add_auth_basic(struct uclient_http *uh)
 	char *auth_buf;
 
 	if (auth_len > 512)
-		return;
+		return -EINVAL;
 
 	auth_buf = alloca(base64_len(auth_len) + 1);
+	if(!auth_buf)
+		return -ENOMEM;
+
 	base64_encode(url->auth, auth_len, auth_buf);
 	ustream_printf(uh->us, "Authorization: Basic %s\r\n", auth_buf);
+
+	return 0;
 }
 
 static char *digest_unquote_sep(char **str)