> > > - About error handling i changed a place being suggested to change > GRUB_ERR_BAD_MODULE, i changed to GRUB_ERR_BUG
ERR_BUG is for an internal bugs aka should never happen. ERR_IO is a better possibility. > + > + > +static void > +dump_variable_data(const char *variable_name, grub_guid_t *variable_guid) > +{ > + grub_efi_status_t status; > + grub_efi_uint32_t attributes; > + grub_size_t data_size; > + void *data; > + > + status = grub_efi_get_variable_with_attributes(variable_name, > variable_guid, > + &data_size, &data, > &attributes); > + if (status != GRUB_EFI_SUCCESS) > + { > + grub_error(GRUB_ERR_BUG, "Failed to retrieve variable data 0x%" > PRIxGRUB_EFI_UINTN_T, status); > Error messages start with lowercase. + return; > + } > + > + grub_printf("Attributes:\n"); > Needs translation > + if (attributes & GRUB_EFI_VARIABLE_NON_VOLATILE) > + grub_printf(N_("\tNon-Volatile\n")); > N_ doesn't translate, only marks for translation. You need to use printf_ or simple _. Here and following. > + > + variable_name = grub_malloc(variable_name_size); > Here and in following: buffer size is in char16s, not bytes, so you need to use calloc with size argument equal to size of(char16s) > + if (!variable_name) > + return grub_errno; > + *variable_name = 0; /* Start with empty string */ > + > + while (1) > + { > + status = r->get_next_variable_name(&variable_name_size, > variable_name, &vendor_guid); > + if (status == GRUB_EFI_NOT_FOUND) > + break; > You don't handle EFI_BUFFER_TOO_SMALL > + variable_name_string = grub_realloc(variable_name_string, > variable_name_size); You need variable_name_size * GRUB_MAX_UTF8_PER_UTF16 + 1 bytes to hold UTF-8 string. > + if (variable_name_string == NULL) > + return grub_errno; > Here you have a memory leak > + grub_utf16_to_utf8(variable_name_string, variable_name, > variable_name_size); > You need to set last char to \0. Look at other users > + grub_printf("%pG-%s\n",&vendor_guid, variable_name_string); > + dump_variable_data((char*)variable_name_string, > &vendor_guid); > + } > + > + grub_free(variable_name); > + grub_free(variable_name_string); > + return GRUB_ERR_NONE; > +} > + > +static grub_err_t > +grub_cmd_lsefivar (grub_command_t cmd __attribute__((unused)), > + int argc , char **argv) > +{ > + if (argc == 0) > + { > + grub_printf("Usage: lsefivar [-l]\n"); > + return GRUB_ERR_BAD_ARGUMENT; > + } > Please use extcmd for argument parsing and documentation > + if (!grub_strcmp(argv[0], "-l")) > + return dump_efi_variables(); > + > + return GRUB_ERR_NONE; > +} > + > +static grub_command_t cmd; > + > +GRUB_MOD_INIT(lsefivar) > +{ > + cmd = grub_register_command("lsefivar", grub_cmd_lsefivar, NULL, > N_("Display UEFI variables.")); > +} > +GRUB_MOD_FINI(lsefivar) > +{ > + grub_unregister_command(cmd); > +} > -- > 2.49.0 > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel > Regards Vladimir 'phcoder' Serbinenko
_______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel