[Rpm-maint] [rpm-software-management/rpm] debug edit build generation is endian dependent when cross-compiling? (#171)

Mark Wielaard mjw at redhat.com
Mon Mar 6 13:24:23 UTC 2017


On Sun, 2017-03-05 at 09:48 -0800, Jeff Johnson wrote:
> For rpm portability with older versions of elfutils, this harmless sanity check might be useful:
> 
> (excuse the different hash functions in use in the patch snippet below)
> @@ -1533,40 +1493,12 @@
>    /* Now format the build ID bits in hex to print out.  */
>    {   
>      const uint8_t * id = (uint8_t *)build_id->d_buf + build_id_offset;
> -    char hex[build_id_size * 2 + 1];
> -    int n = snprintf (hex, 3, "%02" PRIx8, id[0]);
> -    assert (n == 2);
> -    for (i = 1; i < (int)build_id_size; ++i)
> -      {
> -       n = snprintf (&hex[i * 2], 3, "%02" PRIx8, id[i]);
> -       assert (n == 2);
> -      }
> +    char *hex = pgpHexStr(id, build_id_size);
>      puts (hex);
> +    free(hex);
>    }   
>  }

I don't understand this hunk. What is it attempting to do?

Also I assume you posted the reverse patch?

> -/* It avoided the segment fault while file's bss offset have a large number.
> -   See https://bugzilla.redhat.com/show_bug.cgi?id=1019707
> -       https://bugzilla.redhat.com/show_bug.cgi?id=1020842 for detail. */

This is indeed a bug in elfutils, fixed in elfutils 0.162.
But also only occurs for bogus/bad ELF files in the first place.

> -void valid_file(int fd)
> -{
> -  Elf *elf = elf_begin (fd, ELF_C_RDWR, NULL);
> -  if (elf == NULL)
> -  {
> -    error (1, 0, "elf_begin: %s", elf_errmsg (-1));
> -    return;
> -  }
> -
> -  elf_flagelf (elf, ELF_C_SET, ELF_F_LAYOUT);
> -    
> -  if (elf_update (elf, ELF_C_WRITE) < 0)
> -    error (1, 0, "elf_update: %s", elf_errmsg (-1));
> -
> -  elf_end (elf);
> -
> -  return;
> -}

So this opens and closes the ELF file and tries to write it out to disk,
but since nothing changed all this does is make libelf do a layout check
of all headers. Where it would notice nothing changed, so ELF_C_WRITE
would not actually write something out. Except if it does see a
discrepancy and might "correct" a header field. It sounds slightly safer
to do an ELF_C_UPDATE so that nothing might accidentally be written out.

Although it might indeed catch the issue with the bogus ELF file earlier
(and so prevent a crash with a buggy elfutils) I am not sure it is
really the task of rpm/debugedit to make sure the user doesn't have
bogus/bad ELF files and/or an old/buggy libelf implementation. But if
you don't mind opening/closing/reading the ELF file twice this might
indeed not be that expensive (compared to all the other work debugedit
does). It is somewhat bogus and obscure though.

Cheers,

Mark


More information about the Rpm-maint mailing list