packages/pc-parts.c: fix bug in extended partition logic

When compiled with gcc 12 packages/pc-parts.c generates the following error:

/root/packages/pc-parts.c:243:64: error: array subscript 1 is outside array bounds of 'struct pc_partition[1]' [-Werror=array-bounds]
  243 |                         cur_table = ext_start + __le32_to_cpu(p[1].start_sect);
      |                                                               ~^~~
/root/include/libc/byteorder.h:12:13: note: in definition of macro '__bswap32'
   12 |         ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) | \
      |             ^
/root/packages/pc-parts.c:243:49: note: in expansion of macro '__le32_to_cpu'
  243 |                         cur_table = ext_start + __le32_to_cpu(p[1].start_sect);
      |                                                 ^~~~~~~~~~~~~
/root/packages/pc-parts.c:143:13: note: at offset 16 into object of size 16 allocated by 'malloc'
  143 |         p = malloc(sizeof(struct pc_partition));
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [rules.mak:191: target/packages/pc-parts.o] Error 1
make[1]: Leaving directory '/root/obj-ppc'

Upon inspection this appears to be a genuine bug whereby the attempt to access
the second extended partition entry incorrectly accesses the memory beyond the
end of the aligned copy of the first extended partition entry.

Copy the second extended partition entry into aligned extended partition buffer
and access the values from there to resolve the issue.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
1 file changed