From: Tom Carroll Date: Tue, 18 May 2021 06:58:23 +0000 (-0700) Subject: Correct calculation of base64 encode buffer length. X-Git-Tag: v8.20~178 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5b42aa777136a10ee7895c94f0e10d9c1f1609d0;p=users%2Fdwmw2%2Fopenconnect.git Correct calculation of base64 encode buffer length. In the previous formulation, it would first multiple then divide. It would then promote to unsigned int. The formula would overflow for large len. For example, needed = 2 when len == INT_MAX. In the revised formulation, it is promoted, divided, then multiplied. The revised calculation avoids the overflow and computes needed correctly over len in {0, 1, ..., INT_MAX}. For len == INT_MAX, needed is correctly computed as 2863311533. Signed-off-by: Tom Carroll --- diff --git a/http-auth.c b/http-auth.c index 8c3270b7..d6e2c6b7 100644 --- a/http-auth.c +++ b/http-auth.c @@ -119,7 +119,7 @@ void buf_append_base64(struct oc_text_buf *buf, const void *bytes, int len, if (!buf || buf->error) return; - unsigned int needed = (4 * (len + 2) / 3) + 1; + unsigned int needed = ((len + 2u) / 3) * 4 + 1; if (line_len) needed += needed / line_len;