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

Invalid custom plugin output target is not handled correctly #267

Closed
atc0005 opened this issue Oct 17, 2024 · 0 comments · Fixed by #268
Closed

Invalid custom plugin output target is not handled correctly #267

atc0005 opened this issue Oct 17, 2024 · 0 comments · Fixed by #268
Assignees
Labels
bug Something isn't working output/plugin plugin output intended for monitoring system ingest
Milestone

Comments

@atc0005
Copy link
Owner

atc0005 commented Oct 17, 2024

I spotted this while working on #264:

go-nagios/nagios.go

Lines 398 to 407 in 55589e5

// SetOutputTarget assigns a target for Nagios plugin output. By default
// output is emitted to os.Stdout.
func (p *Plugin) SetOutputTarget(w io.Writer) {
// Guard against potential nil argument.
if w == nil {
p.outputSink = os.Stdout
}
p.outputSink = w
}

The nil handling check should return early to prevent the custom (invalid) value from being used as the output target.

@atc0005 atc0005 added bug Something isn't working output/plugin plugin output intended for monitoring system ingest labels Oct 17, 2024
@atc0005 atc0005 added this to the v0.17.0 milestone Oct 17, 2024
@atc0005 atc0005 self-assigned this Oct 17, 2024
atc0005 added a commit that referenced this issue Oct 17, 2024
New tests:

- `TestPluginSetOutputTargetIsValidWithValidInput`
  - basic assertion to show that the method works as intended
    with valid/expected input
- TestPluginSetOutputTargetIsValidWithInvalidInput
  - asserts that when given an invalid output target that the
    default/fallback output target is used instead

The second test is currently failing, highlighting the logic
bug currently affecting the `Plugin.SetOutputTarget` method.

refs GH-267
atc0005 added a commit that referenced this issue Oct 17, 2024
Correctly fallback to default output target when an invalid
output target is provided.

refs GH-267
atc0005 added a commit that referenced this issue Oct 17, 2024
New tests:

- `TestPluginSetOutputTargetIsValidWithValidInput`
  - basic assertion to show that the method works as intended
    with valid/expected input
- TestPluginSetOutputTargetIsValidWithInvalidInput
  - asserts that when given an invalid output target that the
    default/fallback output target is used instead

The second test is currently failing, highlighting the logic
bug currently affecting the `Plugin.SetOutputTarget` method.

refs GH-267
atc0005 added a commit that referenced this issue Oct 17, 2024
Correctly fallback to default output target when an invalid
output target is provided.

refs GH-267
atc0005 added a commit that referenced this issue Oct 20, 2024
Update `TestPluginSetOutputTargetIsValidWithInvalidInput` to
not just assert that plugin.outputSink is set when an invalid
output target is specified, but also that it is specifically
set to the default plugin output target as intended.

- refs GH-268
- refs GH-267
atc0005 added a commit that referenced this issue Oct 20, 2024
Update `TestPluginSetOutputTargetIsValidWithInvalidInput` to
not just assert that plugin.outputSink is set when an invalid
output target is specified, but also that it is specifically
set to the default plugin output target as intended.

- refs GH-268
- refs GH-267
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working output/plugin plugin output intended for monitoring system ingest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant