Skip to content

Commit

Permalink
efi_loadopt_optional_data_size: add efi_error() trace code
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Jones <[email protected]>
  • Loading branch information
vathpela committed Aug 11, 2016
1 parent f572ead commit f238fa7
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/loadopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,49 @@ __attribute__((__nonnull__ (1)))
__attribute__((__visibility__ ("default")))
efi_loadopt_optional_data_size(efi_load_option *opt, size_t size)
{
size_t sz;
ssize_t sz;
ssize_t ret;
uint8_t *p;

if (size < sizeof(*opt))
ret = size;
if (ret < (ssize_t)sizeof(*opt)) {
efi_error("load option size is too small for header (%zd/%zd)",
ret, sizeof(*opt));
return -1;
size -= sizeof(*opt);
if (size < opt->file_path_list_length)
}
ret -= sizeof(*opt);
if (ret < opt->file_path_list_length) {
efi_error("load option size is too small for path (%zd/%d)",
size, opt->file_path_list_length);
return -1;
size -= opt->file_path_list_length;
}
ret -= opt->file_path_list_length;
if (ret < 0) {
efi_error("leftover size is negative (%zd)", ret);
return -1;
}
/* "size" as the limit means sz will be size or less in all cases; no
* need to test it. if it /is/ size, there's no optional data. */
sz = ucs2size(opt->description, size);
sz = ucs2size(opt->description, ret);
p = (uint8_t *)(opt->description) + sz;
size -= sz;
ret -= sz;
if (ret < 0) {
efi_error("leftover size is negative (%zd)", ret);
return -1;
}

if (!efidp_is_valid((const_efidp)p, opt->file_path_list_length))
if (!efidp_is_valid((const_efidp)p, opt->file_path_list_length)) {
efi_error("efi device path is not valid");
return -1;
}
sz = efidp_size((const_efidp)p);
if (sz != opt->file_path_list_length)
if (sz != opt->file_path_list_length) {
efi_error("size does not match file path size (%zd/%d)",
sz, opt->file_path_list_length);
return -1;
}

return size;
return ret;
}

int
Expand Down

0 comments on commit f238fa7

Please sign in to comment.