]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: memory leak in efi_capsule_scan_dir()
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Sun, 11 Apr 2021 04:53:04 +0000 (06:53 +0200)
committerHeinrich Schuchardt <xypron.glpk@gmx.de>
Sat, 17 Apr 2021 18:01:32 +0000 (20:01 +0200)
If realloc() fails, we should free the old buffer.

Fixes: c74cd8bd08d1: ("efi_loader: capsule: add capsule_on_disk support")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
lib/efi_loader/efi_capsule.c

index 9df9c35084c491f6960141497b6e4d86a592f2a8..691eda5e0d1421ba89198c650a25e584873a29d9 100644 (file)
@@ -756,8 +756,11 @@ static efi_status_t efi_capsule_scan_dir(u16 ***files, unsigned int *num)
                tmp_size = dirent_size;
                ret = EFI_CALL((*dirh->read)(dirh, &tmp_size, dirent));
                if (ret == EFI_BUFFER_TOO_SMALL) {
+                       struct efi_file_info *old_dirent = dirent;
+
                        dirent = realloc(dirent, tmp_size);
                        if (!dirent) {
+                               dirent = old_dirent;
                                ret = EFI_OUT_OF_RESOURCES;
                                goto err;
                        }