summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Copybara-Service <copybara-worker@google.com>2022-07-27 07:36:45 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-07-27 07:36:45 -0700
commit51f6d868c8463ac13492d504cbc034e91b43a461 (patch)
tree10c507fd967ae616f5201d03ae852037ded016c2
parentb0787ae6bcd7fc9bc7dc572dcc6d8ee83cd9b0d9 (diff)
parent0e0d8054dc5b8090668eed5f376d218ff2b50225 (diff)
Merge pull request #1223 from ElijahPepe:fix/implement-snprintf-safely
PiperOrigin-RevId: 463581990 Change-Id: I47359d4d2d2fcd2365b5ff9a5c3b61b5751e4ed2
-rw-r--r--absl/synchronization/mutex.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/absl/synchronization/mutex.cc b/absl/synchronization/mutex.cc
index 52e2455d..64177360 100644
--- a/absl/synchronization/mutex.cc
+++ b/absl/synchronization/mutex.cc
@@ -36,6 +36,7 @@
#include <algorithm>
#include <atomic>
#include <cinttypes>
+#include <cstddef>
#include <thread> // NOLINT(build/c++11)
#include "absl/base/attributes.h"
@@ -430,7 +431,11 @@ static void PostSynchEvent(void *obj, int ev) {
char buffer[ABSL_ARRAYSIZE(pcs) * 24];
int pos = snprintf(buffer, sizeof (buffer), " @");
for (int i = 0; i != n; i++) {
- pos += snprintf(&buffer[pos], sizeof (buffer) - pos, " %p", pcs[i]);
+ int b = snprintf(&buffer[pos], sizeof(buffer) - pos, " %p", pcs[i]);
+ if (b < 0 || static_cast<size_t>(b) >= sizeof(buffer) - pos) {
+ break;
+ }
+ pos += b;
}
ABSL_RAW_LOG(INFO, "%s%p %s %s", event_properties[ev].msg, obj,
(e == nullptr ? "" : e->name), buffer);