RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
  Module: rpm                              Date:   23-Mar-2017 19:31:19
  Branch: rpm-5_4                          Handle: 2017032318311900

  Modified files:           (Branch: rpm-5_4)
    rpm                     CHANGES
    rpm/tools               debugedit.c

  Log:
    - debugedit: bug fixes.

  Summary:
    Revision    Changes     Path
    1.3501.2.526+1  -0      rpm/CHANGES
    2.23.2.21   +41 -52     rpm/tools/debugedit.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.3501.2.525 -r1.3501.2.526 CHANGES
  --- rpm/CHANGES       6 Mar 2017 17:52:54 -0000       1.3501.2.525
  +++ rpm/CHANGES       23 Mar 2017 18:31:19 -0000      1.3501.2.526
  @@ -1,4 +1,5 @@
   5.4.17 -> 5.4.18:
  +    - jbj: debugedit: bug fixes.
       - jbj: debugedit: upgrade to handle resizable elf section.
       - jbj: debugedit: sync changes before upgrading.
       - jbj: header: fix: test args before immutable region trailer memcpy 
(PLD).
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/tools/debugedit.c
  ============================================================================
  $ cvs diff -u -r2.23.2.20 -r2.23.2.21 debugedit.c
  --- rpm/tools/debugedit.c     6 Mar 2017 17:52:55 -0000       2.23.2.20
  +++ rpm/tools/debugedit.c     23 Mar 2017 18:31:19 -0000      2.23.2.21
  @@ -1186,7 +1186,7 @@
            {
              const char *file = (const char *) optr;
              const char *file_path = NULL;
  -           if (t->replace_dirs)
  +           if (t->replace_files)
                {
                  file_path = skip_dir_prefix (file, base_dir);
                  if (file_path != NULL)
  @@ -1509,12 +1509,16 @@
                                     comp_dir, base_dir, dest_dir);
                          else
                            {
  -                           /* Add one or more slashes in between to
  -                              fill up all space (replacement must be
  -                              of the same length). */
  +                           /* Add zero (if no file part), one or more
  +                              slashes in between the new dest_dir and the
  +                              file name to fill up all space (replacement
  +                              DW_FORM_string must be of the same length).
  +                              We don't need to copy the old file name (if
  +                              any) or the zero terminator, because those
  +                              are already at the end of the string.  */
                              memcpy (ptr, dest_dir, dest_len);
                              memset (ptr + dest_len, '/',
  -                                   orig_len - new_len + 1);
  +                                   orig_len - new_len);
                            }
                        }
                    }
  @@ -2355,20 +2359,6 @@
   static const pgpHashAlgo algorithms[] = { PGPHASHALGO_MD5,
     PGPHASHALGO_SHA1, PGPHASHALGO_SHA256, PGPHASHALGO_SHA384, 
PGPHASHALGO_SHA512 };
   
  -#ifdef       DYING
  -static size_t _rpmDigestLength(pgpHashAlgo algorithm)
  -{
  -  switch (algorithm) {
  -  default:                   return 0;
  -  case PGPHASHALGO_MD5:              return 128/8;
  -  case PGPHASHALGO_SHA1:     return 160/8;
  -  case PGPHASHALGO_SHA256:   return 256/8;
  -  case PGPHASHALGO_SHA384:   return 384/8;
  -  case PGPHASHALGO_SHA512:   return 512/8;
  -  }
  -}
  -#endif
  -
   /* Compute a fresh build ID bit-string from the editted file contents.  */
   static void
   handle_build_id (DSO *dso, Elf_Data *build_id,
  @@ -2594,40 +2584,25 @@
          break;
        case SHT_NOTE:
          if (do_build_id
  -           && build_id == NULL && (dso->shdr[i].sh_flags & SHF_ALLOC))
  +           && build_id == 0 && (dso->shdr[i].sh_flags & SHF_ALLOC))
            {
              /* Look for a build-ID note here.  */
  +           size_t off = 0;
  +           GElf_Nhdr nhdr;
  +           size_t name_off;
  +           size_t desc_off;
              Elf_Data *data = elf_getdata (elf_getscn (dso->elf, i), NULL);
  -           Elf32_Nhdr nh;
  -           Elf_Data dst =
  -             {
  -               .d_version = EV_CURRENT, .d_type = ELF_T_NHDR,
  -               .d_buf = &nh, .d_size = sizeof nh
  -             };
  -           Elf_Data src = dst;
  -           src.d_buf = data->d_buf;
  -           assert (sizeof (Elf32_Nhdr) == sizeof (Elf64_Nhdr));
  -           while ((char *) data->d_buf + data->d_size -
  -                  (char *) src.d_buf > (int) sizeof nh
  -                  && elf32_xlatetom (&dst, &src, dso->ehdr.e_ident[EI_DATA]))
  -             {
  -               Elf32_Word len = sizeof nh + nh.n_namesz;
  -               len = (len + 3) & ~3;
  -
  -               if (nh.n_namesz == sizeof "GNU" && nh.n_type == 3
  -                   && !memcmp ((char *) src.d_buf + sizeof nh, "GNU", sizeof 
"GNU"))
  -                 {
  -                   build_id = data;
  -                   build_id_offset = (char *) src.d_buf + len -
  -                                     (char *) data->d_buf;
  -                   build_id_size = nh.n_descsz;
  -                   break;
  -                 }
  -
  -               len += nh.n_descsz;
  -               len = (len + 3) & ~3;
  -               src.d_buf = (char *) src.d_buf + len;
  -             }
  +           while ((off = gelf_getnote (data, off,
  +                                       &nhdr, &name_off, &desc_off)) > 0)
  +             if (nhdr.n_type == NT_GNU_BUILD_ID
  +                 && nhdr.n_namesz == sizeof "GNU"
  +                 && (memcmp ((char *)data->d_buf + name_off, "GNU",
  +                             sizeof "GNU") == 0))
  +               {
  +                 build_id = data;
  +                 build_id_offset = desc_off;
  +                 build_id_size = nhdr.n_descsz;
  +               }
            }
          break;
        default:
  @@ -2635,6 +2610,20 @@
        }
       }
   
  +  /* Normally we only need to explicitly update the section headers
  +     and data when any section data changed size. But because of a bug
  +     in elfutils before 0.169 we will have to update and write out all
  +     section data if any data has changed (when ELF_F_LAYOUT was
  +     set). https://sourceware.org/bugzilla/show_bug.cgi?id=21199 */
  +  bool need_update = need_strp_update || need_stmt_update;
  +
  +#if !_ELFUTILS_PREREQ (0, 169)
  +  /* string replacements or build_id updates don't change section size. */
  +  need_update = (need_update
  +              || need_string_replacement
  +              || (do_build_id && build_id != NULL));
  +#endif
  +
     /* We might have changed the size of some debug sections. If so make
        sure the section headers are updated and the data offsets are
        correct. We set ELF_F_LAYOUT above because we don't want libelf
  @@ -2644,7 +2633,7 @@
        anything for the phdrs allocated sections. Keep the offset of
        allocated sections so they are at the same place in the file. Add
        unallocated ones after the allocated ones. */
  -  if (dso->phnum != 0 && (need_strp_update || need_stmt_update))
  +  if (dso->phnum != 0 && need_update)
       {
         Elf *elf = dso->elf;
         GElf_Off last_offset;
  @@ -2684,7 +2673,7 @@
   
          /* A bug in elfutils before 0.169 means we have to write out
             all section data, even when nothing changed.
  -          <A 
HREF="https://sourceware.org/bugzilla/show_bug.cgi?id=21199";>https://sourceware.org/bugzilla/show_bug.cgi?id=21199</A>
 */
  +          https://sourceware.org/bugzilla/show_bug.cgi?id=21199 */
   #if !_ELFUTILS_PREREQ (0, 169)
          if (shdr->sh_type != SHT_NOBITS)
            {
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to