Commit 51f6d868 by Copybara-Service

Merge pull request #1223 from ElijahPepe:fix/implement-snprintf-safely

PiperOrigin-RevId: 463581990
Change-Id: I47359d4d2d2fcd2365b5ff9a5c3b61b5751e4ed2
parents b0787ae6 0e0d8054
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include <cinttypes> #include <cinttypes>
#include <cstddef>
#include <thread> // NOLINT(build/c++11) #include <thread> // NOLINT(build/c++11)
#include "absl/base/attributes.h" #include "absl/base/attributes.h"
...@@ -430,7 +431,11 @@ static void PostSynchEvent(void *obj, int ev) { ...@@ -430,7 +431,11 @@ static void PostSynchEvent(void *obj, int ev) {
char buffer[ABSL_ARRAYSIZE(pcs) * 24]; char buffer[ABSL_ARRAYSIZE(pcs) * 24];
int pos = snprintf(buffer, sizeof (buffer), " @"); int pos = snprintf(buffer, sizeof (buffer), " @");
for (int i = 0; i != n; i++) { 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, ABSL_RAW_LOG(INFO, "%s%p %s %s", event_properties[ev].msg, obj,
(e == nullptr ? "" : e->name), buffer); (e == nullptr ? "" : e->name), buffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment