Merge tag 'u-boot-atmel-fixes-2021.01-b' of https://gitlab.denx.de/u-boot/custodians...
[platform/kernel/u-boot.git] / lib / efi_loader / efi_file.c
index 140116d..72b7ec1 100644 (file)
@@ -8,9 +8,11 @@
 #include <common.h>
 #include <charset.h>
 #include <efi_loader.h>
+#include <log.h>
 #include <malloc.h>
 #include <mapmem.h>
 #include <fs.h>
+#include <part.h>
 
 /* GUID for file system information */
 const efi_guid_t efi_file_system_info_guid = EFI_FILE_SYSTEM_INFO_GUID;
@@ -347,6 +349,11 @@ static efi_status_t file_read(struct file_handle *fh, u64 *buffer_size,
        efi_status_t ret;
        loff_t file_size;
 
+       if (!buffer) {
+               ret = EFI_INVALID_PARAMETER;
+               return ret;
+       }
+
        ret = efi_get_file_size(fh, &file_size);
        if (ret != EFI_SUCCESS)
                return ret;
@@ -412,6 +419,8 @@ static efi_status_t dir_read(struct file_handle *fh, u64 *buffer_size,
                fh->dent = dent;
                return EFI_BUFFER_TOO_SMALL;
        }
+       if (!buffer)
+               return EFI_INVALID_PARAMETER;
        fh->dent = NULL;
 
        *buffer_size = required_size;
@@ -441,7 +450,7 @@ static efi_status_t EFIAPI efi_file_read(struct efi_file_handle *file,
 
        EFI_ENTRY("%p, %p, %p", file, buffer_size, buffer);
 
-       if (!buffer_size || !buffer) {
+       if (!buffer_size) {
                ret = EFI_INVALID_PARAMETER;
                goto error;
        }
@@ -634,7 +643,7 @@ static efi_status_t EFIAPI efi_file_getinfo(struct efi_file_handle *file,
                utf8_utf16_strcpy(&dst, filename);
        } else if (!guidcmp(info_type, &efi_file_system_info_guid)) {
                struct efi_file_system_info *info = buffer;
-               disk_partition_t part;
+               struct disk_partition part;
                efi_uintn_t required_size;
                int r;
 
@@ -714,7 +723,7 @@ static efi_status_t EFIAPI efi_file_setinfo(struct efi_file_handle *file,
                        goto out;
                }
                /* Check for renaming */
-               new_file_name = malloc(utf16_utf8_strlen(info->file_name));
+               new_file_name = malloc(utf16_utf8_strlen(info->file_name) + 1);
                if (!new_file_name) {
                        ret = EFI_OUT_OF_RESOURCES;
                        goto out;