summaryrefslogtreecommitdiff
path: root/libs/binder/Debug.cpp
diff options
context:
space:
mode:
author Martijn Coenen <maco@google.com> 2017-05-08 09:24:15 -0700
committer Steven Moreland <smoreland@google.com> 2019-04-02 16:42:45 -0700
commitd40633b00180bf7c3b81fb693b96e50583e9292f (patch)
treeddb9f1e7df05a5c69f1f1f3ee519bdd8a44a3205 /libs/binder/Debug.cpp
parenta9ed1a6486545ffc5bffca561d6f8991e7d5a578 (diff)
Fix debug output.
If we have fewer bytes left in the buffer than the output alignment, we would read out of bounds and output (partially) incorrect data. Test: debug output is correct (cherry picked from commit 0d9dda2b69c47707e9fdf39d68b04b8edf5623ef) Bug: 129785390 Change-Id: I66913c58295ccd8e1955a73a17f6eed45ca6cd1e
Diffstat (limited to 'libs/binder/Debug.cpp')
-rw-r--r--libs/binder/Debug.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/libs/binder/Debug.cpp b/libs/binder/Debug.cpp
index f38bbb2f32..a1c2a8be08 100644
--- a/libs/binder/Debug.cpp
+++ b/libs/binder/Debug.cpp
@@ -221,7 +221,11 @@ void printHexData(int32_t indent, const void *buf, size_t length,
for (word = 0; word < bytesPerLine; ) {
- const size_t startIndex = word+(alignment-(alignment?1:0));
+ size_t align_offset = alignment-(alignment?1:0);
+ if (remain > 0 && (size_t)remain <= align_offset) {
+ align_offset = remain - 1;
+ }
+ const size_t startIndex = word+align_offset;
for (index = 0; index < alignment || (alignment == 0 && index < bytesPerLine); index++) {