Skip to content

Commit

Permalink
Recover if Parse panics and set error (#6140)
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
  • Loading branch information
devguyio authored Feb 8, 2022
1 parent 6b9499f commit 20718e2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/apis/eventing/v1/trigger_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import (
"regexp"

cesqlparser "github.com/cloudevents/sdk-go/sql/v2/parser"
"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
"knative.dev/pkg/apis"
"knative.dev/pkg/kmp"
"knative.dev/pkg/logging"

"knative.dev/eventing/pkg/apis/feature"
)
Expand Down Expand Up @@ -198,6 +200,14 @@ func ValidateCESQLExpression(ctx context.Context, expression string) (errs *apis
if expression == "" {
return nil
}
// Need to recover in case Parse panics
defer func() {
if r := recover(); r != nil {
logging.FromContext(ctx).Debug("Warning! Calling CESQL Parser panicked. Treating expression as invalid.", zap.Any("recovered value", r), zap.String("CESQL", expression))
errs = apis.ErrInvalidValue(expression, apis.CurrentField)
}
}()

if _, err := cesqlparser.Parse(expression); err != nil {
return apis.ErrInvalidValue(expression, apis.CurrentField, err.Error())
}
Expand Down

0 comments on commit 20718e2

Please sign in to comment.