]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix memory leak in xlat_base64
authorPhilippe Wooding <philippe.wooding@networkradius.com>
Fri, 7 Dec 2018 13:52:25 +0000 (14:52 +0100)
committerPhilippe Wooding <philippe.wooding@networkradius.com>
Fri, 21 Dec 2018 14:44:56 +0000 (15:44 +0100)
src/lib/server/xlat_func.c

index 6e8a70c0d255d77eb5f910dad3ddea456d4f1f44..f64b808cfdfc7b061261d44249452c88370e126e 100644 (file)
@@ -1405,6 +1405,7 @@ static xlat_action_t base64_xlat(TALLOC_CTX *ctx, fr_cursor_t *out,
        ssize_t         elen;
        char            *buff;
        fr_value_box_t  *vb;
+
        /*
         *      If there's no input, there's no output
         */
@@ -1415,19 +1416,20 @@ static xlat_action_t base64_xlat(TALLOC_CTX *ctx, fr_cursor_t *out,
                return XLAT_ACTION_FAIL;
        }
 
-       MEM(vb = fr_value_box_alloc_null(ctx));
        alen = FR_BASE64_ENC_LENGTH((*in)->vb_length);
        MEM(buff = talloc_array(ctx, char, alen + 1));
 
        elen = fr_base64_encode(buff, alen + 1, (*in)->vb_octets, (*in)->vb_length);
        if (elen < 0) {
                RPEDEBUG("Base64 encoding failed");
-               talloc_free(vb);
+               talloc_free(buff);
                return XLAT_ACTION_FAIL;
        }
 
        rad_assert((size_t)elen <= alen);
 
+       MEM(vb = fr_value_box_alloc_null(ctx));
+
        if (fr_value_box_bstrsnteal(vb, vb, NULL, &buff, elen, false) < 0) {
                RPEDEBUG("Failed assigning encoded data buffer to box");
                talloc_free(vb);