#include <part.h>
#include <sandboxblockdev.h>
#include <asm-generic/unaligned.h>
+#include <linux/compat.h> /* U16_MAX */
#ifdef CONFIG_SANDBOX
const efi_guid_t efi_guid_host_dev = U_BOOT_HOST_DEV_GUID;
{
struct efi_device_path_file_path *fp;
void *buf, *start;
- unsigned dpsize = 0, fpsize;
+ size_t dpsize = 0, fpsize;
if (desc)
dpsize = dp_part_size(desc, part);
fpsize = sizeof(struct efi_device_path) +
2 * (utf8_utf16_strlen(path) + 1);
+ if (fpsize > U16_MAX)
+ return NULL;
+
dpsize += fpsize;
start = buf = dp_alloc(dpsize + sizeof(END));
fp = buf;
fp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
fp->dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH;
- fp->dp.length = fpsize;
+ fp->dp.length = (u16)fpsize;
path_to_uefi(fp->str, path);
buf += fpsize;
*file = efi_dp_from_file(((!is_net && device) ? desc : NULL),
part, filename);
+ if (!file)
+ return EFI_INVALID_PARAMETER;
+
return EFI_SUCCESS;
}