Skip to content

Commit

Permalink
in_winevtlog: Prepare buffer before notified the actual size
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 authored and edsiper committed Jun 21, 2024
1 parent ccd24c7 commit f5737c0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions plugins/in_winevtlog/winevtlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,25 +289,36 @@ DWORD render_system_event(EVT_HANDLE event, PEVT_VARIANT *system, unsigned int *
PWSTR get_message(EVT_HANDLE metadata, EVT_HANDLE handle, unsigned int *message_size)
{
WCHAR* buffer = NULL;
WCHAR* previous_buffer = NULL;
DWORD status = ERROR_SUCCESS;
DWORD buffer_size = 0;
DWORD buffer_size = 512;
DWORD buffer_used = 0;
LPVOID format_message_buffer;
WCHAR* message = NULL;
char *error_message = NULL;

buffer = flb_malloc(sizeof(WCHAR) * buffer_size);
if (!buffer) {
flb_error("failed to premalloc message buffer");

goto cleanup;
}

// Get the size of the buffer
if (!EvtFormatMessage(metadata, handle, 0, 0, NULL,
EvtFormatMessageEvent, buffer_size, buffer, &buffer_used)) {
status = GetLastError();
if (ERROR_INSUFFICIENT_BUFFER == status) {
buffer_size = buffer_used;
buffer = flb_malloc(sizeof(WCHAR) * buffer_size);
previous_buffer = buffer;
buffer = flb_realloc(previous_buffer, sizeof(WCHAR) * buffer_size);
if (!buffer) {
flb_error("failed to malloc message buffer");
flb_free(previous_buffer);

goto cleanup;
}

if (!EvtFormatMessage(metadata,
handle,
0xffffffff,
Expand Down

0 comments on commit f5737c0

Please sign in to comment.