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

in_winevtlog: Permit absence of publisher metadata #8974

Merged
merged 2 commits into from
Jun 21, 2024
Merged
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
20 changes: 15 additions & 5 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 Expand Up @@ -415,15 +426,14 @@ PWSTR get_description(EVT_HANDLE handle, LANGID langID, unsigned int *message_si
}
values = (PEVT_VARIANT)buffer;

/* Metadata can be NULL because forwarded events do not have an
* associated publisher metadata. */
metadata = EvtOpenPublisherMetadata(
NULL, // TODO: Remote handle
values[0].StringVal,
NULL,
MAKELCID(langID, SORT_DEFAULT),
0);
if (metadata == NULL) {
goto cleanup;
}

message = get_message(metadata, handle, message_size);

Expand Down
Loading