From b34127ac831b7860e5505a95f4c254bf503f1df6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 15 Dec 2022 20:52:44 +0000 Subject: httpd: drop unnecessary AND ops from base-64 We only use unsigned chars, so we can let truncation do its thing and not overflow. --- mwrap_httpd.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mwrap_httpd.h b/mwrap_httpd.h index e5790aa..606ae20 100644 --- a/mwrap_httpd.h +++ b/mwrap_httpd.h @@ -361,7 +361,7 @@ static void write_b64_url(FILE *fp, const uint8_t *in, size_t len) "abcdefghijklmnopqrstuvwxyz" "0123456789-_"; uint8_t o[4]; while (len > 3) { - o[0] = b64[(in[0] >> 2) & 0x3f]; + o[0] = b64[in[0] >> 2]; o[1] = b64[((in[0] << 4) | (in[1] >> 4)) & 0x3f]; o[2] = b64[((in[1] << 2) | (in[2] >> 6)) & 0x3f]; o[3] = b64[in[2] & 0x3f]; @@ -372,7 +372,7 @@ static void write_b64_url(FILE *fp, const uint8_t *in, size_t len) if (len) { size_t i = 2; - o[0] = b64[(in[0] >> 2) & 0x3f]; + o[0] = b64[in[0] >> 2]; o[1] = b64[((in[0] << 4) | (--len ? (in[1] >> 4) : 0)) & 0x3f]; if (len) o[i++] = b64[((in[1] << 2) | @@ -410,11 +410,11 @@ static bool b64_url_decode(const void *ptr, size_t *len) case 0: u = c << 2; break; case 1: *out++ = u | c >> 4; - u = (c & 0xf) << 4; + u = c << 4; break; case 2: *out++ = u | c >> 2; - u = (c & 0x3) << 6; + u = c << 6; break; case 3: *out++ = u | c; } -- cgit v1.2.3-24-ge0c7