-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix defer unsafe Close vulnerability
Signed-off-by: Subbarao Meduri <[email protected]>
- Loading branch information
1 parent
bc2dc3d
commit 97ab504
Showing
11 changed files
with
72 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -427,7 +427,13 @@ func FetchUserProjectList(token string, url string) []string { | |
writeError(fmt.Sprintf("failed to send http request: %v", err)) | ||
return []string{} | ||
} | ||
defer resp.Body.Close() | ||
|
||
defer func() { | ||
err := resp.Body.Close() | ||
if err != nil { | ||
klog.Errorf("failed to close response body: %v", err) | ||
} | ||
}() | ||
|
||
var projects projectv1.ProjectList | ||
err = json.NewDecoder(resp.Body).Decode(&projects) | ||
|
@@ -451,14 +457,18 @@ func GetUserName(token string, url string) string { | |
writeError(fmt.Sprintf("failed to send http request: %v", err)) | ||
return "" | ||
} | ||
defer resp.Body.Close() | ||
|
||
user := userv1.User{} | ||
err = json.NewDecoder(resp.Body).Decode(&user) | ||
if err != nil { | ||
klog.Errorf("failed to decode response json body: %v", err) | ||
resp.Body.Close() | ||
Check warning Code scanning / SonarCloud Errors unhandled. See more on SonarCloud Warning
Errors unhandled. See more on SonarCloud
|
||
return "" | ||
} | ||
err = resp.Body.Close() | ||
if err != nil { | ||
klog.Errorf("failed to close response body: %v", err) | ||
} | ||
|
||
return user.Name | ||
} | ||
|
This file contains 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 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