Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output-json: drop eve records that are too long #12165

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/output-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer **buffer)
return 0;
}

int OutputJsonBuilderBuffer(
void OutputJsonBuilderBuffer(
ThreadVars *tv, const Packet *p, Flow *f, JsonBuilder *js, OutputJsonThreadCtx *ctx)
{
LogFileCtx *file_ctx = ctx->file_ctx;
Expand All @@ -981,13 +981,23 @@ 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git message says "This also fixes the call to MemBufferExpand which is supposed be
passed the amount to expand by, not the new size required." , however it seems the opposite happens here: total is passed.

Wonder if we should just grow to a next multiple of 4k (or PAGESIZE) that fits

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;
}
}
}

MemBufferWriteRaw((*buffer), jb_ptr(js), (uint32_t)jslen);
LogFileWrite(file_ctx, *buffer);

return 0;
}

static inline enum LogFileType FileTypeFromConf(const char *typestr)
Expand Down
3 changes: 2 additions & 1 deletion 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 All @@ -103,7 +104,7 @@ JsonBuilder *CreateEveHeader(const Packet *p, enum OutputJsonLogDirection dir,
JsonBuilder *CreateEveHeaderWithTxId(const Packet *p, enum OutputJsonLogDirection dir,
const char *event_type, JsonAddrInfo *addr, uint64_t tx_id, OutputJsonCtx *eve_ctx);
int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer **buffer);
int OutputJsonBuilderBuffer(
void OutputJsonBuilderBuffer(
ThreadVars *tv, const Packet *p, Flow *f, JsonBuilder *js, OutputJsonThreadCtx *ctx);
OutputInitResult OutputJsonInitCtx(ConfNode *);

Expand Down
Loading