]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Don't crash when decoding empty base64 strings
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 20 Jan 2024 02:18:02 +0000 (20:18 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 20 Jan 2024 02:30:25 +0000 (20:30 -0600)
src/lib/unlang/xlat_builtin.c
src/tests/keywords/base64

index 38b276a80148eccf328e5f5576dc5d1d58c4eac0..b5824a811a2ce55ac7cc7764afd4a2d28f19b9f6 100644 (file)
@@ -44,6 +44,7 @@ RCSID("$Id$")
 #include <freeradius-devel/util/misc.h>
 #include <freeradius-devel/util/rand.h>
 #include <freeradius-devel/util/sha1.h>
+#include <freeradius-devel/util/value.h>
 
 #ifdef HAVE_OPENSSL_EVP_H
 #  include <freeradius-devel/tls/openssl_user_macros.h>
@@ -1783,6 +1784,17 @@ static xlat_action_t xlat_func_base64_decode(TALLOC_CTX *ctx, fr_dcursor_t *out,
 
        XLAT_ARGS(args, &in);
 
+       /*
+        *      Pass empty arguments through
+        *
+        *      FR_BASE64_DEC_LENGTH produces 2 for empty strings...
+        */
+       if (in->vb_length == 0) {
+               fr_value_box_list_remove(args, in);
+               fr_dcursor_append(out, in);
+               return XLAT_ACTION_DONE;
+       }
+
        alen = FR_BASE64_DEC_LENGTH(in->vb_length);
        MEM(vb = fr_value_box_alloc_null(ctx));
        if (alen > 0) {
index f23ea7ff256d7ded87cf59b0f345f50ec22952e4..e6f6c5cfffd0b79b6d33af354ff1bbce883c63e0 100644 (file)
@@ -100,6 +100,13 @@ if (!(&test_output == 'IDk4Nz4=')) {
        test_fail
 }
 
+# Something weird causes this test not to parse
+# &test_octets := %base64.decode("")
+#if (!(&test_octets == "")) {
+#      test_fail
+#}
+
+# Regression test, this used to crash...
 &test_octets := %base64.decode(Zm9v)
 if (!(&test_octets == "foo")) {
        debug_request