Skip to content

Commit 2ba4827

Browse files
cosmo0920edsiper
authored andcommitted
in_winevtlog: Plug possible SEGV occurrence paths
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent ad2e9fc commit 2ba4827

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

plugins/in_winevtlog/pack.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ static int pack_wstr(struct winevtlog_config *ctx, const wchar_t *wstr)
4242
int size;
4343
char *buf;
4444
UINT code_page = CP_UTF8;
45-
LPCSTR defaultChar = L" ";
45+
const char *defaultChar = " ";
46+
47+
if (!wstr) {
48+
return -1;
49+
}
4650

4751
if (ctx->use_ansi) {
4852
code_page = CP_ACP;
@@ -110,6 +114,9 @@ static int pack_binary(struct winevtlog_config *ctx, PBYTE bin, size_t length)
110114
static int pack_guid(struct winevtlog_config *ctx, const GUID *guid)
111115
{
112116
LPOLESTR p = NULL;
117+
if (!guid) {
118+
return -1;
119+
}
113120

114121
if (FAILED(StringFromCLSID(guid, &p))) {
115122
return -1;
@@ -639,14 +646,24 @@ void winevtlog_pack_event(PEVT_VARIANT system, WCHAR *message,
639646
/* ActivityID */
640647
ret = flb_log_event_encoder_append_body_cstring(ctx->log_encoder, "ActivityID");
641648

642-
if (pack_guid(ctx, system[EvtSystemActivityID].GuidVal)) {
649+
if (EvtVarTypeNull != system[EvtSystemActivityID].Type) {
650+
if (pack_guid(ctx, system[EvtSystemActivityID].GuidVal)) {
651+
pack_nullstr(ctx);
652+
}
653+
}
654+
else {
643655
pack_nullstr(ctx);
644656
}
645657

646658
/* Related ActivityID */
647659
ret = flb_log_event_encoder_append_body_cstring(ctx->log_encoder, "RelatedActivityID");
648660

649-
if (pack_guid(ctx, system[EvtSystemRelatedActivityID].GuidVal)) {
661+
if (EvtVarTypeNull != system[EvtSystemRelatedActivityID].Type) {
662+
if (pack_guid(ctx, system[EvtSystemRelatedActivityID].GuidVal)) {
663+
pack_nullstr(ctx);
664+
}
665+
}
666+
else {
650667
pack_nullstr(ctx);
651668
}
652669

0 commit comments

Comments
 (0)