95a93d
commit e8b9832af19e5975fb2a9dbe729eaba0373c781f
95a93d
Author: Mark Wielaard <mark@klomp.org>
95a93d
Date:   Mon Dec 3 00:03:39 2018 +0100
95a93d
95a93d
    libebl: Fix reading GNU_PROPERTY_STACK_SIZE reading from 32bit notes.
95a93d
    
95a93d
    When reading a GNU_PROPERTY_STACK_SIZE we need to use the proper data
95a93d
    type. GElf_Addr is 64bit always and when reading a 32bit size part of
95a93d
    it would not be initialized. Use either Elf32_Addr or Elf64_Addr to
95a93d
    read and print the data.
95a93d
    
95a93d
    Add 32bit and 64bit, little and big endian testcases.
95a93d
    
95a93d
    Signed-off-by: Mark Wielaard <mark@klomp.org>
95a93d
95a93d
diff --git a/libebl/eblobjnote.c b/libebl/eblobjnote.c
95a93d
index 58ac86d..c19ea37 100644
95a93d
--- a/libebl/eblobjnote.c
95a93d
+++ b/libebl/eblobjnote.c
95a93d
@@ -360,15 +360,22 @@ ebl_object_note (Ebl *ebl, uint32_t namesz, const char *name, uint32_t type,
95a93d
 		  if (prop.pr_type == GNU_PROPERTY_STACK_SIZE)
95a93d
 		    {
95a93d
 		      printf ("STACK_SIZE ");
95a93d
-		      if (prop.pr_datasz == 4 || prop.pr_datasz == 8)
95a93d
+		      union
95a93d
+			{
95a93d
+			  Elf64_Addr a64;
95a93d
+			  Elf32_Addr a32;
95a93d
+			} addr;
95a93d
+		      if ((elfclass == ELFCLASS32 && prop.pr_datasz == 4)
95a93d
+			  || (elfclass == ELFCLASS64 && prop.pr_datasz == 8))
95a93d
 			{
95a93d
-			  GElf_Addr addr;
95a93d
 			  in.d_type = ELF_T_ADDR;
95a93d
 			  out.d_type = ELF_T_ADDR;
95a93d
 			  in.d_size = prop.pr_datasz;
95a93d
-			  out.d_size = sizeof (addr);
95a93d
+			  out.d_size = prop.pr_datasz;
95a93d
 			  in.d_buf = (void *) desc;
95a93d
-			  out.d_buf = (void *) &addr;
95a93d
+			  out.d_buf = (elfclass == ELFCLASS32
95a93d
+				       ? (void *) &addr.a32
95a93d
+				       : (void *) &addr.a64);
95a93d
 
95a93d
 			  if (gelf_xlatetom (ebl->elf, &out, &in,
95a93d
 					     elfident[EI_DATA]) == NULL)
95a93d
@@ -376,7 +383,10 @@ ebl_object_note (Ebl *ebl, uint32_t namesz, const char *name, uint32_t type,
95a93d
 			      printf ("%s\n", elf_errmsg (-1));
95a93d
 			      return;
95a93d
 			    }
95a93d
-			  printf ("%#" PRIx64 "\n", addr);
95a93d
+			  if (elfclass == ELFCLASS32)
95a93d
+			    printf ("%#" PRIx32 "\n", addr.a32);
95a93d
+			  else
95a93d
+			    printf ("%#" PRIx64 "\n", addr.a64);
95a93d
 			}
95a93d
 		      else
95a93d
 			printf (" (garbage datasz: %" PRIx32 ")\n",