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

fix(core, common): handle error for closing io streams #1098

Merged
merged 1 commit into from
Feb 7, 2023

Conversation

rksharma95
Copy link
Collaborator

Purpose of PR?:
There some unhandled errors in common and core packages reported by the gosec in the CI, all are related to the potential errors may occurred while closing the io stream. This PR fixes those issues.

[/home/runner/work/KubeArmor/KubeArmor/KubeArmor/common/common.go:254] - G307 (CWE-703): Deferring unsafe method "Close" on type "io.WriteCloser" (Confidence: HIGH, Severity: MEDIUM)
    253: 	go func() {
  > 254: 		defer stdin.Close()
    255: 		_, _ = io.WriteString(stdin, "values written to stdin are passed to cmd's standard input")

[/home/runner/work/KubeArmor/KubeArmor/KubeArmor/common/common.go:224] - G307 (CWE-703): Deferring unsafe method "Close" on type "io.WriteCloser" (Confidence: HIGH, Severity: MEDIUM)
    223: 	go func() {
  > 224: 		defer stdin.Close()
    225: 		_, _ = io.WriteString(stdin, "values written to stdin are passed to cmd's standard input")

[/home/runner/work/KubeArmor/KubeArmor/KubeArmor/core/kubeUpdate.go:2292] - G307 (CWE-703): Deferring unsafe method "Close" on type "io.ReadCloser" (Confidence: HIGH, Severity: MEDIUM)
    2291: 		if resp := K8s.WatchK8sHostSecurityPolicies(); resp != nil {
  > 2292: 			defer resp.Body.Close()
    2293: 

[/home/runner/work/KubeArmor/KubeArmor/KubeArmor/core/kubeUpdate.go:505] - G307 (CWE-703): Deferring unsafe method "Close" on type "io.ReadCloser" (Confidence: HIGH, Severity: MEDIUM)
    504: 		if resp := K8s.WatchK8sPods(); resp != nil {
  > 505: 			defer resp.Body.Close()
    506: 

[/home/runner/work/KubeArmor/KubeArmor/KubeArmor/core/kubeUpdate.go:99] - G307 (CWE-703): Deferring unsafe method "Close" on type "io.ReadCloser" (Confidence: HIGH, Severity: MEDIUM)
    98: 		if resp := K8s.WatchK8sNodes(); resp != nil {
  > 99: 			defer resp.Body.Close()

Does this PR introduce a breaking change?
No
If the changes in this PR are manually verified, list down the scenarios covered::

Additional information for reviewer? :
Mention if this PR is part of any design or a continuation of previous PRs

Checklist:

  • Bug fix.
  • PR Title follows the convention of <type>(<scope>): <subject>

Signed-off-by: rksharma95 <ramakant@accuknox.com>
@achrefbensaad achrefbensaad self-requested a review February 7, 2023 09:47
Copy link
Member

@achrefbensaad achrefbensaad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants