commit | 00cb016d89afa752d3fdebe60f9e7e27b45da2e6 | [log] [tgz] |
---|---|---|
author | Steven Moreland <smoreland@google.com> | Tue Aug 04 21:37:54 2020 +0000 |
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Tue Aug 04 21:37:54 2020 +0000 |
tree | 197fd9bb4360c52b8e18f57dad0741ae5754333d | |
parent | f69c785d81abb72c2018e2433d348e78daea0bd7 [diff] | |
parent | 372ad415e6f55a5c78276011a67b68bd8c14aecf [diff] |
Merge "libutils: check vsnprintf error" into oc-dev am: a03d37d542 Original change: https://googleplex-android-review.googlesource.com/c/platform/system/core/+/12254459 Change-Id: Id247c7079c146da8eaf52f098027d5daa25ce8d8
diff --git a/libutils/String8.cpp b/libutils/String8.cpp index ad0e72e..8f9c9f7 100644 --- a/libutils/String8.cpp +++ b/libutils/String8.cpp
@@ -346,8 +346,14 @@ n = vsnprintf(NULL, 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);