summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-08-12 21:45:34 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-08-12 21:45:34 +0000
commita790490ec973cd1799384a367da59d0200591c0a (patch)
tree1443e8741df9aa77cb6410d23f52c97df24fe96b
parent6072de17cd812daf238092695f26a552d3122f8c (diff)
parentbad50ed24f9d48d001fcedd332d59f162dc3432d (diff)
downloadcore-android11-s1-release.tar.gz
Merge cherrypicks of [12364563, 12364330, 12364331, 12364332, 12363743, 12364605, 12363956, 12363957, 12363958, 12364309, 12364483, 12364484, 12364564, 12364333, 12364334, 12364335, 12364336, 12364337, 12364607] into rvc-releaseandroid-11.0.0_r5android-11.0.0_r4android-11.0.0_r25android-11.0.0_r17android11-s1-releaseandroid11-release
Change-Id: Ie9f4226d1f67acd2680aac6e366b4c3b0e30933e
-rw-r--r--libutils/String8.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/libutils/String8.cpp b/libutils/String8.cpp
index d13548e4c..9d50e0bc5 100644
--- a/libutils/String8.cpp
+++ b/libutils/String8.cpp
@@ -322,8 +322,14 @@ status_t String8::appendFormatV(const char* fmt, va_list args)
n = vsnprintf(nullptr, 0, fmt, tmp_args);
va_end(tmp_args);
- if (n != 0) {
+ if (n < 0) return UNKNOWN_ERROR;
+
+ if (n > 0) {
size_t oldLength = length();
+ if ((size_t)n > SIZE_MAX - 1 ||
+ oldLength > SIZE_MAX - (size_t)n - 1) {
+ return NO_MEMORY;
+ }
char* buf = lockBuffer(oldLength + n);
if (buf) {
vsnprintf(buf + oldLength, n + 1, fmt, args);