]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
dm: crypto: Check malloc return value
authorFrancois Berder <fberder@outlook.fr>
Thu, 4 Dec 2025 19:34:12 +0000 (20:34 +0100)
committerTom Rini <trini@konsulko.com>
Fri, 2 Jan 2026 21:51:54 +0000 (15:51 -0600)
tmp_buffer is allocated using malloc but failure
is not handled.
This commit ensures that we do not use a NULL pointer
if malloc fails.

Signed-off-by: Francois Berder <fberder@outlook.fr>
drivers/crypto/aes/aes-uclass.c

index 745c6ce57a9600f47a9a3a5ba77a16cfe3e58687..5bdd3d736c497cd92bbdb33de8dd4e9267d1264b 100644 (file)
@@ -156,13 +156,17 @@ int dm_aes_cmac(struct udevice *dev, u8 *src, u8 *dst, u32 num_aes_blocks)
        /* Process all blocks except last by calling engine several times per dma buffer size */
        if (num_aes_blocks > 1) {
                tmp_buffer = malloc(AES_BLOCK_LENGTH * min(num_aes_blocks - 1, TMP_BUFFER_LEN));
+               if (!tmp_buffer)
+                       return -1;
                while (num_aes_blocks > 1) {
                        u32 blocks = min(num_aes_blocks - 1, TMP_BUFFER_LEN);
 
                        /* Encrypt the current remaining set of blocks that fits in tmp buffer */
                        ret = dm_aes_cbc_encrypt(dev, tmp_block, src, tmp_buffer, blocks);
-                       if (ret)
+                       if (ret) {
+                               free(tmp_buffer);
                                return -1;
+                       }
 
                        num_aes_blocks -= blocks;
                        src += blocks * AES_BLOCK_LENGTH;