-
Notifications
You must be signed in to change notification settings - Fork 2k
in_winevtlog: fix crash when all channels are missing and ignore_missing_channels is enabled #12318
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
Open
lecaros
wants to merge
2
commits into
master
Choose a base branch
from
lecaros-fix-winevtlog-empty-channels-crash
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+201
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
|
||
| /* Fluent Bit | ||
| * ========== | ||
| * Copyright (C) 2015-2026 The Fluent Bit Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include <fluent-bit.h> | ||
| #include <fluent-bit/flb_time.h> | ||
| #include "flb_tests_runtime.h" | ||
|
|
||
| /* | ||
| * Channels that must not exist on the host. The names are deliberately | ||
| * implausible; the tests rely on subscription to them failing with | ||
| * ERROR_EVT_CHANNEL_NOT_FOUND. | ||
| */ | ||
| #define MISSING_CHANNEL_A "FlbTestMissingChannelA" | ||
| #define MISSING_CHANNEL_B "FlbTestMissingChannelB" | ||
|
|
||
| /* | ||
| * All channels of the instance are missing and tolerated: the engine must | ||
| * start, survive collection cycles and stop cleanly. Before the fix, | ||
| * ctx->active_channel was NULL and the first collection cycle crashed the | ||
| * process (NULL dereference in mk_list_foreach). | ||
| */ | ||
| void flb_test_winevtlog_all_channels_missing_ignored(void) | ||
| { | ||
| int ret; | ||
| flb_ctx_t *ctx; | ||
| int in_ffd; | ||
| int out_ffd; | ||
|
|
||
| ctx = flb_create(); | ||
| TEST_CHECK(ctx != NULL); | ||
|
|
||
| in_ffd = flb_input(ctx, (char *) "winevtlog", NULL); | ||
| TEST_CHECK(in_ffd >= 0); | ||
| ret = flb_input_set(ctx, in_ffd, | ||
| "channels", MISSING_CHANNEL_A, | ||
| "ignore_missing_channels", "true", | ||
| "interval_sec", "1", | ||
| NULL); | ||
| TEST_CHECK(ret == 0); | ||
|
|
||
| out_ffd = flb_output(ctx, (char *) "null", NULL); | ||
| TEST_CHECK(out_ffd >= 0); | ||
| flb_output_set(ctx, out_ffd, "match", "*", NULL); | ||
|
|
||
| ret = flb_start(ctx); | ||
| TEST_CHECK(ret == 0); | ||
|
|
||
| /* Let at least two collection cycles run (interval_sec=1) */ | ||
| flb_time_msleep(2500); | ||
|
|
||
| flb_stop(ctx); | ||
| flb_destroy(ctx); | ||
| } | ||
|
|
||
| /* Same as above but with several missing channels in one instance */ | ||
| void flb_test_winevtlog_multiple_missing_channels_ignored(void) | ||
| { | ||
| int ret; | ||
| flb_ctx_t *ctx; | ||
| int in_ffd; | ||
| int out_ffd; | ||
|
|
||
| ctx = flb_create(); | ||
| TEST_CHECK(ctx != NULL); | ||
|
|
||
| in_ffd = flb_input(ctx, (char *) "winevtlog", NULL); | ||
| TEST_CHECK(in_ffd >= 0); | ||
| ret = flb_input_set(ctx, in_ffd, | ||
| "channels", MISSING_CHANNEL_A "," MISSING_CHANNEL_B, | ||
| "ignore_missing_channels", "true", | ||
| "interval_sec", "1", | ||
| NULL); | ||
| TEST_CHECK(ret == 0); | ||
|
|
||
| out_ffd = flb_output(ctx, (char *) "null", NULL); | ||
| TEST_CHECK(out_ffd >= 0); | ||
| flb_output_set(ctx, out_ffd, "match", "*", NULL); | ||
|
|
||
| ret = flb_start(ctx); | ||
| TEST_CHECK(ret == 0); | ||
|
|
||
| flb_time_msleep(2500); | ||
|
|
||
| flb_stop(ctx); | ||
| flb_destroy(ctx); | ||
| } | ||
|
|
||
| /* | ||
| * A mix of one existing channel ('Application' always exists on Windows) | ||
| * and one missing channel: the missing one is skipped, the instance keeps | ||
| * working. This was already the behavior before the fix and must not | ||
| * regress. | ||
| */ | ||
| void flb_test_winevtlog_mixed_channels_ignored(void) | ||
| { | ||
| int ret; | ||
| flb_ctx_t *ctx; | ||
| int in_ffd; | ||
| int out_ffd; | ||
|
|
||
| ctx = flb_create(); | ||
| TEST_CHECK(ctx != NULL); | ||
|
|
||
| in_ffd = flb_input(ctx, (char *) "winevtlog", NULL); | ||
| TEST_CHECK(in_ffd >= 0); | ||
| ret = flb_input_set(ctx, in_ffd, | ||
| "channels", "Application," MISSING_CHANNEL_A, | ||
| "ignore_missing_channels", "true", | ||
| "interval_sec", "1", | ||
| NULL); | ||
| TEST_CHECK(ret == 0); | ||
|
|
||
| out_ffd = flb_output(ctx, (char *) "null", NULL); | ||
| TEST_CHECK(out_ffd >= 0); | ||
| flb_output_set(ctx, out_ffd, "match", "*", NULL); | ||
|
|
||
| ret = flb_start(ctx); | ||
| TEST_CHECK(ret == 0); | ||
|
|
||
| flb_time_msleep(2500); | ||
|
|
||
| flb_stop(ctx); | ||
| flb_destroy(ctx); | ||
| } | ||
|
|
||
| /* | ||
| * Without ignore_missing_channels, a missing channel must keep failing | ||
| * initialization (documented behavior: "Subscribe at least one"). | ||
| */ | ||
| void flb_test_winevtlog_missing_channel_fails_without_ignore(void) | ||
| { | ||
| int ret; | ||
| flb_ctx_t *ctx; | ||
| int in_ffd; | ||
| int out_ffd; | ||
|
|
||
| ctx = flb_create(); | ||
| TEST_CHECK(ctx != NULL); | ||
|
|
||
| in_ffd = flb_input(ctx, (char *) "winevtlog", NULL); | ||
| TEST_CHECK(in_ffd >= 0); | ||
| ret = flb_input_set(ctx, in_ffd, | ||
| "channels", MISSING_CHANNEL_A, | ||
| NULL); | ||
| TEST_CHECK(ret == 0); | ||
|
|
||
| out_ffd = flb_output(ctx, (char *) "null", NULL); | ||
| TEST_CHECK(out_ffd >= 0); | ||
| flb_output_set(ctx, out_ffd, "match", "*", NULL); | ||
|
|
||
| ret = flb_start(ctx); | ||
| TEST_CHECK(ret != 0); | ||
|
|
||
| flb_destroy(ctx); | ||
| } | ||
|
|
||
| /* Test list */ | ||
| TEST_LIST = { | ||
| {"all_channels_missing_ignored", | ||
| flb_test_winevtlog_all_channels_missing_ignored}, | ||
| {"multiple_missing_channels_ignored", | ||
| flb_test_winevtlog_multiple_missing_channels_ignored}, | ||
| {"mixed_channels_ignored", | ||
| flb_test_winevtlog_mixed_channels_ignored}, | ||
| {"missing_channel_fails_without_ignore", | ||
| flb_test_winevtlog_missing_channel_fails_without_ignore}, | ||
| {NULL, NULL} | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
ignore_missing_channelsis true andwinevtlog_open_all()returns NULL for a reason other than an absent channel—for example,query_for_channel()returns-1for a malformed structuredevent_query—the unchanged initialization path still accepts that NULL. This guard then makes the collector return forever, so Fluent Bit reports a successful startup while silently ingesting no events. Since the tolerated all-missing case is now represented by a non-NULL empty list, treat a NULL result as fatal during initialization rather than swallowing it here.Useful? React with 👍 / 👎.