From: Arran Cudbard-Bell Date: Sat, 20 Jan 2024 02:18:02 +0000 (-0600) Subject: Don't crash when decoding empty base64 strings X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d21c967734a67b38b146a1266980993c95d14383;p=thirdparty%2Ffreeradius-server.git Don't crash when decoding empty base64 strings --- diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index 38b276a8014..b5824a811a2 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -44,6 +44,7 @@ RCSID("$Id$") #include #include #include +#include #ifdef HAVE_OPENSSL_EVP_H # include @@ -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) { diff --git a/src/tests/keywords/base64 b/src/tests/keywords/base64 index f23ea7ff256..e6f6c5cfffd 100644 --- a/src/tests/keywords/base64 +++ b/src/tests/keywords/base64 @@ -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