1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

Implicit memory aliasing in for loop. (#2530)

Signed-off-by: slayer321 <sachin.maurya7666@gmail.com>
This commit is contained in:
Sachin 2021-10-13 11:03:25 -07:00 committed by GitHub
parent 787d6de696
commit 0d402ec09c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,9 +2,10 @@ package engine
import (
"fmt"
"time"
"github.com/kyverno/kyverno/pkg/engine/context"
"github.com/pkg/errors"
"time"
"github.com/go-logr/logr"
gojmespath "github.com/jmespath/go-jmespath"
@ -54,7 +55,7 @@ func Mutate(policyContext *PolicyContext) (resp *response.EngineResponse) {
var err error
for _, rule := range policy.Spec.Rules {
for i, rule := range policy.Spec.Rules {
if !rule.HasMutate() {
continue
}
@ -101,16 +102,16 @@ func Mutate(policyContext *PolicyContext) (resp *response.EngineResponse) {
err, mutateResp := mutateResource(ruleCopy, policyContext.JSONContext, patchedResource, logger)
if err != nil {
if mutateResp.skip {
ruleResp = ruleResponse(&rule, utils.Mutation, err.Error(), response.RuleStatusSkip)
ruleResp = ruleResponse(&policy.Spec.Rules[i], utils.Mutation, err.Error(), response.RuleStatusSkip)
} else {
ruleResp = ruleResponse(&rule, utils.Mutation, err.Error(), response.RuleStatusError)
ruleResp = ruleResponse(&policy.Spec.Rules[i], utils.Mutation, err.Error(), response.RuleStatusError)
}
} else {
if mutateResp.message == "" {
mutateResp.message = "mutated resource"
}
ruleResp = ruleResponse(&rule, utils.Mutation, mutateResp.message, response.RuleStatusPass)
ruleResp = ruleResponse(&policy.Spec.Rules[i], utils.Mutation, mutateResp.message, response.RuleStatusPass)
ruleResp.Patches = mutateResp.patches
patchedResource = mutateResp.patchedResource
}