Re: [PATCH] grub-module-verifier: report the filename or modname in errors.

2018-09-03 Thread Daniel Kiper
On Wed, Aug 01, 2018 at 12:23:03PM -0400, Peter Jones wrote:
> Make it so that when grub-module-verifier complains of an issue, it tells you
> which module the issue was with.
>
> Signed-off-by: Peter Jones 

Reviewed-by: Daniel Kiper 

Daniel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] grub-module-verifier: report the filename or modname in errors.

2018-08-01 Thread Peter Jones
Make it so that when grub-module-verifier complains of an issue, it tells you
which module the issue was with.

Signed-off-by: Peter Jones 
---
 util/grub-module-verifier.c|  6 ++--
 util/grub-module-verifierXX.c  | 58 ++
 include/grub/module_verifier.h |  4 +--
 3 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/util/grub-module-verifier.c b/util/grub-module-verifier.c
index a79271f6631..03ba1ab437a 100644
--- a/util/grub-module-verifier.c
+++ b/util/grub-module-verifier.c
@@ -157,7 +157,7 @@ main (int argc, char **argv)
 if (strcmp(archs[arch].name, argv[2]) == 0)
   break;
   if (arch == ARRAY_SIZE(archs))
-grub_util_error("unknown arch: %s", argv[2]);
+grub_util_error("%s: unknown arch: %s", argv[1], argv[2]);
 
   for (whitelist = 0; whitelist < ARRAY_SIZE(whitelists); whitelist++)
 if (strcmp(whitelists[whitelist].arch, argv[2]) == 0
@@ -169,8 +169,8 @@ main (int argc, char **argv)
   module_size = grub_util_get_image_size (argv[1]);
   module_img = grub_util_read_image (argv[1]);
   if (archs[arch].voidp_sizeof == 8)
-grub_module_verify64(module_img, module_size, &archs[arch], 
whitelist_empty);
+grub_module_verify64(argv[1], module_img, module_size, &archs[arch], 
whitelist_empty);
   else
-grub_module_verify32(module_img, module_size, &archs[arch], 
whitelist_empty);
+grub_module_verify32(argv[1], module_img, module_size, &archs[arch], 
whitelist_empty);
   return 0;
 }
diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c
index b7025e9e418..29846455622 100644
--- a/util/grub-module-verifierXX.c
+++ b/util/grub-module-verifierXX.c
@@ -160,14 +160,15 @@ find_section (const struct grub_module_verifier_arch 
*arch, Elf_Ehdr *e, const c
 }
 
 static void
-check_license (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
+check_license (const char * const filename,
+  const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
 {
   Elf_Shdr *s = find_section (arch, e, ".module_license");
   if (s && (strcmp ((char *) e + grub_target_to_host(s->sh_offset), 
"LICENSE=GPLv3") == 0
|| strcmp ((char *) e + grub_target_to_host(s->sh_offset), 
"LICENSE=GPLv3+") == 0
|| strcmp ((char *) e + grub_target_to_host(s->sh_offset), 
"LICENSE=GPLv2+") == 0))
 return;
-  grub_util_error ("incompatible license");
+  grub_util_error ("%s: incompatible license", filename);
 }
 
 static Elf_Sym *
@@ -233,10 +234,10 @@ check_symbols (const struct grub_module_verifier_arch 
*arch,
   s = find_section (arch, e, ".moddeps");
 
   if (!s)
-   grub_util_error ("no symbol table and no .moddeps section");
+   grub_util_error ("%s: no symbol table and no .moddeps section", 
modname);
 
   if (!s->sh_size)
-   grub_util_error ("no symbol table and empty .moddeps section");
+   grub_util_error ("%s: no symbol table and empty .moddeps section", 
modname);
 
   return;
 }
@@ -257,7 +258,7 @@ check_symbols (const struct grub_module_verifier_arch *arch,
  break;
 
default:
- return grub_util_error ("unknown symbol type `%d'", (int) type);
+ return grub_util_error ("%s: unknown symbol type `%d'", modname, 
(int) type);
}
 }
 }
@@ -283,7 +284,8 @@ is_symbol_local(Elf_Sym *sym)
 }
 
 static void
-section_check_relocations (const struct grub_module_verifier_arch *arch, void 
*ehdr,
+section_check_relocations (const char * const modname,
+  const struct grub_module_verifier_arch *arch, void 
*ehdr,
   Elf_Shdr *s, size_t target_seg_size)
 {
   Elf_Rel *rel, *max;
@@ -292,7 +294,7 @@ section_check_relocations (const struct 
grub_module_verifier_arch *arch, void *e
 
   symtab = get_symtab (arch, ehdr, &symtabsize, &symtabentsize);
   if (!symtab)
-grub_util_error ("relocation without symbol table");
+grub_util_error ("%s: relocation without symbol table", modname);
 
   for (rel = (Elf_Rel *) ((char *) ehdr + grub_target_to_host (s->sh_offset)),
 max = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_size));
@@ -303,7 +305,7 @@ section_check_relocations (const struct 
grub_module_verifier_arch *arch, void *e
   unsigned i;
 
   if (target_seg_size < grub_target_to_host (rel->r_offset))
-   grub_util_error ("reloc offset is out of the segment");
+   grub_util_error ("%s: reloc offset is out of the segment", modname);
 
   grub_uint32_t type = ELF_R_TYPE (grub_target_to_host (rel->r_info));
 
@@ -316,17 +318,17 @@ section_check_relocations (const struct 
grub_module_verifier_arch *arch, void *e
   if (arch->supported_relocations[i] != -1)
continue;
   if (!arch->short_relocations)
-   grub_util_error ("unsupported relocation 0x%x", type);
+   grub_util_error ("%s: unsupported relocation 0x%x", modname, type);
   for (i = 0; arch->short_relocations[i] != -1; i++)
if (type == arch->short_reloc