Skip to contentSkip to conversation

x86/mkelf32: correct off-by-1 in empty PHDR checking loop

PATCH In review Jan Beulich 2 participants 2 messages Nov 24

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mkelf32: correct off-by-1 in empty PHDR checking loop

To read the trailing PHDR, we need to seek to its start position within the file, not its ending one.

Fixes 54279f87ecbc ("x86/build: make linking work again with ld incapable of generating build ID")
xen/arch/x86/boot/mkelf32.c +2 -1
@@ -320,7 +320,8 @@ int main(int argc, char **argv)
     while ( in64_ehdr.e_phnum > num_phdrs )
     {
         (void)lseek(infd,
-                    in64_ehdr.e_phoff + in64_ehdr.e_phnum * sizeof(in64_phdr),
+                    in64_ehdr.e_phoff + (in64_ehdr.e_phnum - 1) *
+                                        sizeof(in64_phdr),
                     SEEK_SET);
         do_read(infd, &in64_phdr, sizeof(in64_phdr));
         endianadjust_phdr64(&in64_phdr);