31 lines
1.1 KiB
Diff
31 lines
1.1 KiB
Diff
From 82ca5634b513cca4bf40fd99e97fef6652dcc75f Mon Sep 17 00:00:00 2001
|
|
From: Omar Sandoval <osandov@osandov.com>
|
|
Date: Tue, 8 Jun 2021 12:05:42 -0700
|
|
Subject: [PATCH] libdrgn: fix copying value to big-endian from little-endian
|
|
|
|
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>
|
|
---
|
|
libdrgn/serialize.h | 2 +-
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
|
diff --git a/libdrgn/serialize.h b/libdrgn/serialize.h
|
|
index da3ba91a..0f4783f3 100644
|
|
--- a/libdrgn/serialize.h
|
|
+++ b/libdrgn/serialize.h
|
|
@@ -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);
|