Fix accounting of last written position when updating ELF files.
authorUlrich Drepper <drepper@redhat.com>
Wed, 21 Jan 2009 23:22:11 +0000 (15:22 -0800)
committerUlrich Drepper <drepper@redhat.com>
Wed, 21 Jan 2009 23:22:11 +0000 (15:22 -0800)
libelf/ChangeLog
libelf/elf32_updatefile.c

index 36efd90..38d352d 100644 (file)
@@ -1,3 +1,10 @@
+2009-01-21  Ulrich Drepper  <drepper@redhat.com>
+
+       * elf32_updatefile.c (elfXX_updatemmap): When skipping non-NOBITS
+       sections we haven't loaded, update last_position based on scn_start,
+       not based on old value.  Don't run the loop for the dummy section 0.
+       (elfXX_updatefile): Don't run the loop for the dummy section 0.
+
 2009-01-10  Ulrich Drepper  <drepper@redhat.com>
 
        * libelfP.h (_): We only have one translation domain, elfutils.
index e88f4a4..111e1d2 100644 (file)
@@ -283,6 +283,13 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
       for (size_t cnt = 0; cnt < shnum; ++cnt)
        {
          Elf_Scn *scn = scns[cnt];
+         if (scn->index == 0)
+           {
+             /* The dummy section header entry.  It should not be
+                possible to make this "section" as dirty.  */
+             assert ((scn->flags & ELF_F_DIRTY) == 0);
+             continue;
+           }
 
          ElfW2(LIBELFBITS,Shdr) *shdr = scn->shdr.ELFW(e,LIBELFBITS);
 
@@ -362,9 +369,9 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
                dl = dl->next;
              }
            while (dl != NULL);
-         else if (shdr->sh_type != SHT_NOBITS && scn->index != 0)
+         else if (shdr->sh_type != SHT_NOBITS)
            /* We have to trust the existing section header information.  */
-           last_position += shdr->sh_size;
+           last_position = scn_start + shdr->sh_size;
 
          scn->flags &= ~ELF_F_DIRTY;
        }
@@ -616,6 +623,13 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum)
       for (size_t cnt = 0; cnt < shnum; ++cnt)
        {
          Elf_Scn *scn = scns[cnt];
+         if (scn->index == 0)
+           {
+             /* The dummy section header entry.  It should not be
+                possible to make this "section" as dirty.  */
+             assert ((scn->flags & ELF_F_DIRTY) == 0);
+             continue;
+           }
 
          ElfW2(LIBELFBITS,Shdr) *shdr = scn->shdr.ELFW(e,LIBELFBITS);
 
@@ -695,7 +709,7 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum)
                dl = dl->next;
              }
            while (dl != NULL);
-         else if (shdr->sh_type != SHT_NOBITS && scn->index != 0)
+         else if (shdr->sh_type != SHT_NOBITS)
            last_offset = scn_start + shdr->sh_size;
 
          /* Collect the section header table information.  */