Skip to content

Commit

Permalink
chore: fix implicit memory aliasing in for loop (#2341)
Browse files Browse the repository at this point in the history
## Description

- Fixed Implicit memory aliasing in for loop -
[gosec](https://github.com/securego/gosec) finding

## Related Issue

Fixes #
<!-- or -->
Relates to #

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Other (security config, docs update, etc)

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed

Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
  • Loading branch information
naveensrinivasan committed Feb 29, 2024
1 parent 22f2598 commit 0ee871d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/cmd/tools/helm/load_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ func addPluginCommands(plugin *plugin.Plugin, baseCmd *cobra.Command, cmds *plug

// Recursively add any sub-commands
for _, cmd := range cmds.Commands {
cmdCopy := cmd
// Create a fake command so that completion can be done for the sub-commands of the plugin
subCmd := &cobra.Command{
// This prevents Cobra from removing the flags. We want to keep the flags to pass them
Expand All @@ -308,7 +309,7 @@ func addPluginCommands(plugin *plugin.Plugin, baseCmd *cobra.Command, cmds *plug
Run: func(_ *cobra.Command, _ []string) {},
}
baseCmd.AddCommand(subCmd)
addPluginCommands(plugin, subCmd, &cmd)
addPluginCommands(plugin, subCmd, &cmdCopy)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/pkg/cluster/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ func (c *Cluster) InitZarfState(initOptions types.ZarfInitOptions) error {
}
// This label will tell the Zarf Agent to ignore this namespace.
namespace.Labels[agentLabel] = "ignore"
if _, err = c.UpdateNamespace(&namespace); err != nil {
namespaceCopy := namespace
if _, err = c.UpdateNamespace(&namespaceCopy); err != nil {
// This is not a hard failure, but we should log it.
message.WarnErrf(err, "Unable to mark the namespace %s as ignored by Zarf Agent", namespace.Name)
}
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/cluster/zarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ func (c *Cluster) StripZarfLabelsAndSecretsFromNamespaces() {
if _, ok := namespace.Labels[agentLabel]; ok {
spinner.Updatef("Removing Zarf Agent label for namespace %s", namespace.Name)
delete(namespace.Labels, agentLabel)
if _, err = c.UpdateNamespace(&namespace); err != nil {
namespaceCopy := namespace
if _, err = c.UpdateNamespace(&namespaceCopy); err != nil {
// This is not a hard failure, but we should log it
spinner.Errorf(err, "Unable to update the namespace labels for %s", namespace.Name)
}
Expand Down

0 comments on commit 0ee871d

Please sign in to comment.