Skip to content

Commit

Permalink
in_winetvlog: Handle buffer allocation error and not mapped error (#9011
Browse files Browse the repository at this point in the history
)

* in_winetvlog: Handle formatting and not mapped error properly

---------

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
  • Loading branch information
cosmo0920 authored Jun 27, 2024
1 parent 060418c commit 13f96f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 12 additions & 3 deletions plugins/in_winevtlog/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ static int pack_sid(struct winevtlog_config *ctx, PSID sid, int extract_sid)
&len, &sid_type)) {
err = GetLastError();
if (err == ERROR_NONE_MAPPED) {
strcpy_s(account, MAX_NAME, "NONE_MAPPED");
flb_plg_debug(ctx->ins, "AccountSid is not mapped. code: %u", err);

goto not_mapped_error;
}
else {
flb_plg_warn(ctx->ins, "LookupAccountSid Error %u", err);
Expand All @@ -296,6 +298,8 @@ static int pack_sid(struct winevtlog_config *ctx, PSID sid, int extract_sid)
if (formatted == NULL) {
flb_plg_warn(ctx->ins, "create result buffer failed");

ret = -1;

goto error;
}

Expand Down Expand Up @@ -327,12 +331,17 @@ static int pack_sid(struct winevtlog_config *ctx, PSID sid, int extract_sid)
return ret;
}

error:
not_mapped_error:
ret = pack_wstr(ctx, wide_sid);

LocalFree(wide_sid);

return -1;
return ret;

error:
LocalFree(wide_sid);

return ret;
}

return ret;
Expand Down
6 changes: 4 additions & 2 deletions plugins/in_winevtlog/winevtlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ PWSTR get_message(EVT_HANDLE metadata, EVT_HANDLE handle, unsigned int *message_
if (!buffer) {
flb_error("failed to premalloc message buffer");

goto cleanup;
goto buffer_error;
}

// Get the size of the buffer
Expand All @@ -316,7 +316,7 @@ PWSTR get_message(EVT_HANDLE metadata, EVT_HANDLE handle, unsigned int *message_
flb_error("failed to malloc message buffer");
flb_free(previous_buffer);

goto cleanup;
goto buffer_error;
}

if (!EvtFormatMessage(metadata,
Expand Down Expand Up @@ -386,6 +386,8 @@ PWSTR get_message(EVT_HANDLE metadata, EVT_HANDLE handle, unsigned int *message_
flb_free(buffer);
}

buffer_error:

return message;
}

Expand Down

0 comments on commit 13f96f9

Please sign in to comment.