summaryrefslogtreecommitdiff
path: root/libs/binder/BufferedTextOutput.cpp
diff options
context:
space:
mode:
author Martijn Coenen <maco@google.com> 2020-01-22 10:46:25 +0100
committer Martijn Coenen <maco@google.com> 2020-01-31 09:04:55 +0000
commit93fe51840ebf2e2ea0c29d3c5aa196e328129469 (patch)
tree8f1f9a511aac5aefc60b0067528ca82c05186f42 /libs/binder/BufferedTextOutput.cpp
parent876a1960e4a264a364ef14634840d5eebd78f01e (diff)
Fix addition/overflow checks.
For unsigned arithmetic, use: (a + b < a) to detect whether a+b wraps (a > c / b) to detect whether a*b > c Bug: 120078455 Test: builds and boots Change-Id: Ic4f4d44f7c0656caa115f90f4cfa130192914949 (cherry picked from commit da2f2fd0f4c4eeb498b4b0541719f4f34faf13e2)
Diffstat (limited to 'libs/binder/BufferedTextOutput.cpp')
-rw-r--r--libs/binder/BufferedTextOutput.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/libs/binder/BufferedTextOutput.cpp b/libs/binder/BufferedTextOutput.cpp
index 857bbf9510..2978b539d7 100644
--- a/libs/binder/BufferedTextOutput.cpp
+++ b/libs/binder/BufferedTextOutput.cpp
@@ -49,9 +49,10 @@ struct BufferedTextOutput::BufferState : public RefBase
}
status_t append(const char* txt, size_t len) {
+ if (len > SIZE_MAX - bufferPos) return NO_MEMORY; // overflow
if ((len+bufferPos) > bufferSize) {
+ if ((len + bufferPos) > SIZE_MAX / 3) return NO_MEMORY; // overflow
size_t newSize = ((len+bufferPos)*3)/2;
- if (newSize < (len+bufferPos)) return NO_MEMORY; // overflow
void* b = realloc(buffer, newSize);
if (!b) return NO_MEMORY;
buffer = (char*)b;