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

next/649/20241128/v1 #12178

Merged
merged 4 commits into from
Nov 29, 2024
Merged
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
2 changes: 0 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2167,7 +2167,6 @@ fi
AM_CONDITIONAL([HAVE_RUST],true)
AC_SUBST([CARGO], [$CARGO])

enable_rust="yes"
rust_compiler_version=$($RUSTC --version)
rustc_version=$(echo "$rust_compiler_version" | sed 's/^.*[[^0-9]]\([[0-9]]*\.[[0-9]]*\.[[0-9]]*\).*$/\1/')
cargo_version_output=$($CARGO --version)
Expand Down Expand Up @@ -2567,7 +2566,6 @@ SURICATA_BUILD_CONF="Suricata Configuration:
Landlock support: ${enable_landlock}
Systemd support: ${enable_systemd}

Rust support: ${enable_rust}
Rust strict mode: ${enable_rust_strict}
Rust compiler path: ${RUSTC}
Rust compiler version: ${rust_compiler_version}
Expand Down
22 changes: 17 additions & 5 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 @@ -980,14 +980,26 @@ 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 remaining = MEMBUFFER_SIZE(*buffer) - MEMBUFFER_OFFSET(*buffer);
if (jslen >= remaining) {
size_t expand_by = jslen + 1 - remaining;
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;
}
}

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
5 changes: 5 additions & 0 deletions src/util-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ int MemBufferExpand(MemBuffer **buffer, uint32_t expand_by) {
return -1;
}

/* Adjust expand_by to next multiple of 4k. */
if (expand_by % 4096 != 0) {
expand_by = expand_by - (expand_by % 4096) + 4096;
}

size_t total_size = (*buffer)->size + sizeof(MemBuffer) + expand_by;

MemBuffer *tbuffer = SCRealloc(*buffer, total_size);
Expand Down
Loading