diff options
author | Heinrich Schuchardt | 2018-09-12 18:43:58 +0200 |
---|---|---|
committer | Alexander Graf | 2018-09-23 21:55:30 +0200 |
commit | 143acd1ef12e8834548b8434fa4a4ca160f4cd23 (patch) | |
tree | 0c866256ed69454e44b91458e81099a0feacc58f /lib/efi_loader/efi_file.c | |
parent | a90bf07afc4363ee69262722ab5802adb7b80e7f (diff) |
efi_loader: check parameters of efi_file_open()
Check the parameters of efi_file_open().
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'lib/efi_loader/efi_file.c')
-rw-r--r-- | lib/efi_loader/efi_file.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index 89d65694da3..92ca4446175 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -202,15 +202,37 @@ static efi_status_t EFIAPI efi_file_open(struct efi_file_handle *file, s16 *file_name, u64 open_mode, u64 attributes) { struct file_handle *fh = to_fh(file); + efi_status_t ret; EFI_ENTRY("%p, %p, \"%ls\", %llx, %llu", file, new_handle, file_name, open_mode, attributes); - *new_handle = file_open(fh->fs, fh, file_name, open_mode, attributes); - if (!*new_handle) - return EFI_EXIT(EFI_NOT_FOUND); + /* Check parameters */ + if (!file || !file || !file_name) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + if (open_mode != EFI_FILE_MODE_READ && + open_mode != (EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE) && + open_mode != (EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | + EFI_FILE_MODE_CREATE)) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + if ((!(open_mode & EFI_FILE_MODE_CREATE) && attributes) || + (attributes & (EFI_FILE_READ_ONLY | ~EFI_FILE_VALID_ATTR))) { + ret = EFI_INVALID_PARAMETER; + goto out; + } - return EFI_EXIT(EFI_SUCCESS); + /* Open file */ + *new_handle = file_open(fh->fs, fh, file_name, open_mode, attributes); + if (*new_handle) + ret = EFI_SUCCESS; + else + ret = EFI_NOT_FOUND; +out: + return EFI_EXIT(ret); } static efi_status_t file_close(struct file_handle *fh) |