Skip to content

Commit

Permalink
libdrgn: fix copying value to big-endian from little-endian
Browse files Browse the repository at this point in the history
copy_lsbytes() doesn't copy enough bytes when copying from a smaller
little-endian value to a larger big-endian value. This was caught by the
test cases for DW_OP_deref{,_size}, but it can affect other places when
debugging a little-endian target from a big-endian host or vice-versa.

Closes #105.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
  • Loading branch information
osandov committed Jun 8, 2021
1 parent 5a03d6b commit 82ca563
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion libdrgn/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static inline void copy_lsbytes(void *dst, size_t dst_size,
} else {
memset(d, 0, dst_size - size);
if (src_little_endian) {
for (size_t i = dst_size - size; i < size; i++)
for (size_t i = dst_size - size; i < dst_size; i++)
d[i] = s[dst_size - 1 - i];
} else {
memcpy(d + dst_size - size, s + src_size - size, size);
Expand Down

0 comments on commit 82ca563

Please sign in to comment.