From 1506a2f62de43b2fa3dc8c7932c3811eb15460cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20D=C3=B6tsch?= Date: Fri, 25 Aug 2023 10:10:54 +0200 Subject: [PATCH] gosec: avoid security warning CWE-118: Implicit memory aliasing in for loop --- command/pool/pool_commands.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/command/pool/pool_commands.go b/command/pool/pool_commands.go index da52bcfb..e1a1aa16 100644 --- a/command/pool/pool_commands.go +++ b/command/pool/pool_commands.go @@ -92,7 +92,15 @@ func (c *poolCommands) lockResource(match matcher.Result, message msg.Message) { c.slackClient.ReplyError(message, err) return } - c.slackClient.SendMessage(message, fmt.Sprintf("`%s` is locked for you until %s!\n%s%s", resource.Resource.Name, resource.LockUntil.Format(time.RFC1123), getFormattedReason(resource.Reason), getAddressesAndFeatures(&resource.Resource))) + c.slackClient.SendMessage( + message, + fmt.Sprintf("`%s` is locked for you until %s!\n%s%s", + resource.Resource.Name, + resource.LockUntil.Format(time.RFC1123), + getFormattedReason(resource.Reason), + getAddressesAndFeatures(resource.Resource), + ), + ) } func (c *poolCommands) unlockResource(match matcher.Result, message msg.Message) { @@ -208,7 +216,7 @@ func (c *poolCommands) listPoolInfo(match matcher.Result, message msg.Message) { messages = append(messages, "*Available:*") free := c.pool.GetFree() for _, f := range free { - messages = append(messages, fmt.Sprintf("`%s`:\n%s\n", f.Name, getAddressesAndFeatures(f))) + messages = append(messages, fmt.Sprintf("`%s`:\n%s\n", f.Name, getAddressesAndFeatures(*f))) } } messages = append(messages, "") @@ -216,7 +224,17 @@ func (c *poolCommands) listPoolInfo(match matcher.Result, message msg.Message) { locked := c.pool.GetLocks("") messages = append(messages, "*Used/Locked:*") for _, l := range locked { - messages = append(messages, fmt.Sprintf("`%s`:\n locked by %s until %s\n%s%s", l.Resource.Name, l.User, l.LockUntil.Format(time.RFC1123), getFormattedReason(l.Reason), getAddressesAndFeatures(&l.Resource))) + messages = append( + messages, + fmt.Sprintf( + "`%s`:\n locked by %s until %s\n%s%s", + l.Resource.Name, + l.User, + l.LockUntil.Format(time.RFC1123), + getFormattedReason(l.Reason), + getAddressesAndFeatures(l.Resource), + ), + ) } } @@ -230,7 +248,7 @@ func getFormattedReason(reason string) string { return fmt.Sprintf("_%s_\n", reason) } -func getAddressesAndFeatures(resource *config.Resource) string { +func getAddressesAndFeatures(resource config.Resource) string { var lines []string lines = append(lines, ">_Addresses:_") for _, address := range resource.Addresses {