diff options
author | Ian-Woo Kim <ianwookim@gmail.com> | 2022-11-30 21:08:59 -0800 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-12-08 08:32:19 -0500 |
commit | 2057c77d08cb8422857d182a3691f98dccd0c7d6 (patch) | |
tree | 2a85671ccc70d2edb75a98518a20e3bcd281c153 | |
parent | 90cd53960f4e712197efc320b3aa104e95345a23 (diff) | |
download | haskell-2057c77d08cb8422857d182a3691f98dccd0c7d6.tar.gz |
Truncate eventlog event for large payload (#20221)
RTS eventlog events for postCapsetVecEvent are truncated if payload
is larger than EVENT_PAYLOAD_SIZE_MAX
Previously, postCapsetVecEvent records eventlog event with payload
of variable size larger than EVENT_PAYLOAD_SIZE_MAX (2^16) without
any validation, resulting in corrupted data.
For example, this happens when a Haskell binary is invoked with very
long command line arguments exceeding 2^16 bytes (see #20221).
Now we check the size of accumulated payload messages incrementally,
and truncate the message just before the payload size exceeds
EVENT_PAYLOAD_SIZE_MAX. RTS will warn the user with a message showing
how many arguments are truncated.
-rw-r--r-- | rts/eventlog/EventLog.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/rts/eventlog/EventLog.c b/rts/eventlog/EventLog.c index 53d5e28a61..dfa9ecc0fb 100644 --- a/rts/eventlog/EventLog.c +++ b/rts/eventlog/EventLog.c @@ -754,7 +754,17 @@ void postCapsetVecEvent (EventTypeNum tag, for (int i = 0; i < argc; i++) { // 1 + strlen to account for the trailing \0, used as separator - size += 1 + strlen(argv[i]); + int increment = 1 + strlen(argv[i]); + if (size + increment > EVENT_PAYLOAD_SIZE_MAX) { + errorBelch("Event size exceeds EVENT_PAYLOAD_SIZE_MAX, record only %" + FMT_Int " out of %" FMT_Int " args", + (long long) i, + (long long) argc); + argc = i; + break; + } else { + size += increment; + } } ACQUIRE_LOCK(&eventBufMutex); |