about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-12-15 20:52:44 +0000
committerEric Wong <mwrap-perl@80x24.org>2022-12-16 09:27:42 +0000
commitb34127ac831b7860e5505a95f4c254bf503f1df6 (patch)
treeac8ed830c42ba5253935ca866d315c6d02a43fa2
parent4dbf07af51e2b560c379324a7551dd247bb52de4 (diff)
downloadmwrap-b34127ac831b7860e5505a95f4c254bf503f1df6.tar.gz
We only use unsigned chars, so we can let truncation do its
thing and not overflow.
-rw-r--r--mwrap_httpd.h8
1 files 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;
                 }