uclient-http: basic auth: Handle memory allocation failure
authorTobias Schramm <tobleminer@gmail.com>
Sun, 18 Feb 2018 12:46:05 +0000 (13:46 +0100)
committerJohn Crispin <john@phrozen.org>
Tue, 20 Feb 2018 07:16:54 +0000 (08:16 +0100)
Allocation of the base64 buffer might fail, resulting in a null
ptr being passed to base64_encode as a target buffer

Signed-off-by: Tobias Schramm <tobleminer@gmail.com>
uclient-http.c

index ef8de988e81499ede0a7c3734879793fc274ebc1..36e2b388cfe707b71fb09b5e23f1c1703326a6d1 100644 (file)
@@ -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)