Fix the conversion macro for .note sections, broken in the case

the ELF file's byte order is not the native byte order.  The
bug is that the variables holding the name and description size
are used (natively) after having been byte-swapped.  The fix is
to calculate sz from them just prior to byte-swapping.

Approved by:	jkoshy@
Obtained from:	Juniper Networks, Inc.
This commit is contained in:
marcel 2014-10-22 01:04:16 +00:00
parent 76382aeb89
commit 3d0d095b21

View File

@ -947,6 +947,11 @@ _libelf_cvt_NOTE_tom(char *dst, size_t dsz, char *src, size_t count,
READ_WORD(src, descsz);
READ_WORD(src, type);
sz = namesz;
ROUNDUP2(sz, 4);
sz += descsz;
ROUNDUP2(sz, 4);
/* Translate. */
SWAP_WORD(namesz);
SWAP_WORD(descsz);
@ -962,11 +967,6 @@ _libelf_cvt_NOTE_tom(char *dst, size_t dsz, char *src, size_t count,
dst += sizeof(Elf_Note);
count -= hdrsz;
ROUNDUP2(namesz, 4);
ROUNDUP2(descsz, 4);
sz = namesz + descsz;
if (count < sz || dsz < sz) /* Buffers are too small. */
return (0);