Skip to content

Commit

Permalink
output-json: drop eve records that are too long
Browse files Browse the repository at this point in the history
In the situation where the mem buffer cannot be expanded to the
requested size, log a one time warning per JSON logger with bit of the
log message that is being dropped, then return.

This also fixes the call to MemBufferExpand which is supposed by
passed the amount to expand by, not the new size required.

Ticket: OISF#7300
  • Loading branch information
jasonish committed Nov 27, 2024
1 parent bd7d38e commit 06eb242
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/output-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,20 @@ int OutputJsonBuilderBuffer(
size_t jslen = jb_len(js);
DEBUG_VALIDATE_BUG_ON(jb_len(js) > UINT32_MAX);
if (MEMBUFFER_OFFSET(*buffer) + jslen >= MEMBUFFER_SIZE(*buffer)) {
MemBufferExpand(buffer, (uint32_t)jslen);
size_t expand_by = MEMBUFFER_OFFSET(*buffer) + jslen + 1;
if (MemBufferExpand(buffer, (uint32_t)expand_by) < 0) {
if (!ctx->too_large_warning) {
/* Log a warning once, and include enough of the log
* message to hopefully identify the event_type. */
char partial[120];
size_t partial_len = MIN(sizeof(partial), jslen);
memcpy(partial, jb_ptr(js), partial_len - 1);
partial[partial_len - 1] = '\0';
SCLogWarning("Formatted JSON EVE record too large, will be dropped: %s", partial);
ctx->too_large_warning = true;
}
return 0;
}
}

MemBufferWriteRaw((*buffer), jb_ptr(js), (uint32_t)jslen);
Expand Down
1 change: 1 addition & 0 deletions src/output-json.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ typedef struct OutputJsonThreadCtx_ {
OutputJsonCtx *ctx;
LogFileCtx *file_ctx;
MemBuffer *buffer;
bool too_large_warning;
} OutputJsonThreadCtx;

json_t *SCJsonString(const char *val);
Expand Down

0 comments on commit 06eb242

Please sign in to comment.