Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lws_b64_decode_string error "base64 must end at end of input" #3339

Open
Vmcsnekke opened this issue Feb 17, 2025 · 0 comments
Open

lws_b64_decode_string error "base64 must end at end of input" #3339

Vmcsnekke opened this issue Feb 17, 2025 · 0 comments

Comments

@Vmcsnekke
Copy link

Vmcsnekke commented Feb 17, 2025

lws_b64_decode_string always fails, see:

[2025/02/17 17:29:31:9128] E: _lws_b64_decode_string: base64 must end at end of input

I looked into it and fixed it (see below a patch). Is there a guide on howto send this upstream?


The external lws_b64_decode_string and internal _lws_b64_decode_string
do not require an input string length, and this is when strlen is used
to get the length and compare it against the
"length-of-the-input-actually-decoded".
The comparison forgets no input string length might be given and so
_lws_b64_decode_string might fail with "base64 must end at end of input".

This can be easily fixed by using strlen right away to pass the
input string length to _lws_b64_decode_string.
---
 lib/misc/base64-decode.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/lib/misc/base64-decode.c b/lib/misc/base64-decode.c
index 8f0a735d..332325cc 100644
--- a/lib/misc/base64-decode.c
+++ b/lib/misc/base64-decode.c
@@ -203,8 +203,7 @@ lws_b64_decode_stateful(struct lws_b64state *s, const char *in, size_t *in_len,
  * returns length of decoded string in out, or -1 if out was too small
  * according to out_size
  *
- * Only reads up to in_len chars, otherwise if in_len is -1 on entry reads until
- * the first NUL in the input.
+ * Only reads up to in_len chars.
  */
 
 static size_t
@@ -213,9 +212,6 @@ _lws_b64_decode_string(const char *in, int in_len, char *out, size_t out_size)
        struct lws_b64state state;
        size_t il = (size_t)in_len, ol = out_size;
 
-       if (in_len == -1)
-               il = strlen(in);
-
        lws_b64_decode_state_init(&state);
        if (lws_b64_decode_stateful(&state, in, &il, (uint8_t *)out, &ol, 1) < 0)
                /* pass on the failure */
@@ -229,10 +225,15 @@ _lws_b64_decode_string(const char *in, int in_len, char *out, size_t out_size)
        return ol;
 }
 
+
+/*
+ * reads until the first NUL in the input.
+ */
+
 int
 lws_b64_decode_string(const char *in, char *out, int out_size)
 {
-       return (int)_lws_b64_decode_string(in, -1, out, (unsigned int)out_size);
+       return (int)_lws_b64_decode_string(in, (int)strlen(in), out, (unsigned int)out_size);
 }
 
 int
-- 
2.47.1


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant