libelf: Fix cross-endian ELF note file / memory conversion
The namesz and descsz variables need to be used in native endianness. The sizes are in native order after swapping in the file to memory case, and before swapping in the memory to file case. This issue was identified for r273443, but the change was applied to the wrong case. Revert r273443 to fix the to-memory case, and apply the equivalent change to the to-file case. Sponsored by: DARPA, AFRL Reviewed by: adrian, brooks, marcel Differential Revision: https://reviews.freebsd.org/D1257
This commit is contained in:
parent
4e88d37a2a
commit
ccbdcd03f2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=275430
@ -947,11 +947,6 @@ _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);
|
||||
@ -967,6 +962,11 @@ _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);
|
||||
|
||||
@ -1005,6 +1005,11 @@ _libelf_cvt_NOTE_tof(char *dst, size_t dsz, char *src, size_t count,
|
||||
descsz = en->n_descsz;
|
||||
type = en->n_type;
|
||||
|
||||
sz = namesz;
|
||||
ROUNDUP2(sz, 4);
|
||||
sz += descsz;
|
||||
ROUNDUP2(sz, 4);
|
||||
|
||||
SWAP_WORD(namesz);
|
||||
SWAP_WORD(descsz);
|
||||
SWAP_WORD(type);
|
||||
@ -1015,11 +1020,6 @@ _libelf_cvt_NOTE_tof(char *dst, size_t dsz, char *src, size_t count,
|
||||
|
||||
src += sizeof(Elf_Note);
|
||||
|
||||
ROUNDUP2(namesz, 4);
|
||||
ROUNDUP2(descsz, 4);
|
||||
|
||||
sz = namesz + descsz;
|
||||
|
||||
if (count < sz)
|
||||
sz = count;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user