commit | 1c2859fb76bb4c4b2330585226cac43e1ac3f263 | [log] [tgz] |
---|---|---|
author | Steven Moreland <smoreland@google.com> | Tue Aug 04 22:03:55 2020 +0000 |
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Tue Aug 04 22:03:55 2020 +0000 |
tree | 683ce939869b5bcc48fcbe12948728fe475eeed4 | |
parent | d6297be44d310c8985ebb3b238ef5fc0c59634c9 [diff] | |
parent | 00cb016d89afa752d3fdebe60f9e7e27b45da2e6 [diff] |
Merge "libutils: check vsnprintf error" into oc-dev am: a03d37d542 am: d8801aaad8 Original change: https://googleplex-android-review.googlesource.com/c/platform/system/core/+/12254459 Change-Id: Ifa0692e4966e78f4e180a2efc53db991177b6006
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);