Fix a cluster of bugs in list EFI environment variables:

1. Size returned for variable name is in bytes, not CHAR16 (the
   UEFI standard is unclear on this, where it is clear on the size of
   the variable).
2. Dynamically allocate the buffers so we can grow them if someone
   defines a super-long variable name.

These two fixes allow me to examine all the variables in my BIOS and
also removes the repeated printing of variables.
This commit is contained in:
imp 2016-09-30 15:41:12 +00:00
parent 622458f472
commit 7cda556b92

View File

@ -814,8 +814,10 @@ command_efi_show(int argc, char *argv[])
EFI_GUID varguid = { 0,0,0,{0,0,0,0,0,0,0,0} };
EFI_GUID matchguid = { 0,0,0,{0,0,0,0,0,0,0,0} };
uint32_t uuid_status;
CHAR16 varname[128];
CHAR16 *varname;
CHAR16 *newnm;
CHAR16 varnamearg[128];
UINTN varalloc;
UINTN varsz;
while ((ch = getopt(argc, argv, "ag:lv:")) != -1) {
@ -910,10 +912,33 @@ command_efi_show(int argc, char *argv[])
* to specify the initial call must be a poiner to a NULL
* character.
*/
varsz = nitems(varname);
varalloc = 1024;
varname = malloc(varalloc);
if (varname == NULL) {
printf("Can't allocate memory to get variables\n");
pager_close();
return (CMD_ERROR);
}
varname[0] = 0;
while ((status = RS->GetNextVariableName(&varsz, varname, &varguid)) !=
EFI_NOT_FOUND) {
while (1) {
varsz = varalloc;
status = RS->GetNextVariableName(&varsz, varname, &varguid);
if (status == EFI_BUFFER_TOO_SMALL) {
varalloc = varsz;
newnm = malloc(varalloc);
if (newnm == NULL) {
printf("Can't allocate memory to get variables\n");
free(varname);
pager_close();
return (CMD_ERROR);
}
memcpy(newnm, varname, varsz);
free(varname);
varname = newnm;
continue; /* Try again with bigger buffer */
}
if (status != EFI_SUCCESS)
break;
if (aflag) {
if (efi_print_var(varname, &varguid, lflag) != CMD_OK)
break;
@ -934,6 +959,7 @@ command_efi_show(int argc, char *argv[])
}
}
}
free(varname);
pager_close();
return (CMD_OK);