Skip to content

Commit 03dcb4b

Browse files
authored
Merge pull request #153939 from yuzefovich/backport25.2-151849
release-25.2: plpgsql: fix handling of annotations for DO blocks
2 parents dcd90be + 07540f6 commit 03dcb4b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pkg/sql/sem/tree/annotation.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package tree
77

8+
import "github.com/cockroachdb/cockroach/pkg/util/buildutil"
9+
810
// AnnotationIdx is the 1-based index of an annotation. AST nodes that can
911
// be annotated store such an index (unique within that AST).
1012
type AnnotationIdx int32
@@ -22,6 +24,12 @@ func (n AnnotatedNode) GetAnnotation(ann *Annotations) interface{} {
2224
if n.AnnIdx == NoAnnotation {
2325
return nil
2426
}
27+
if (len(*ann) < int(n.AnnIdx) || int(n.AnnIdx) < 1) && !buildutil.CrdbTestBuild {
28+
// Avoid index-out-of bounds panics in production builds. The impact is
29+
// that the node will be treated as if it doesn't have the annotation,
30+
// which is better than the process crash.
31+
return nil
32+
}
2533
return ann.Get(n.AnnIdx)
2634
}
2735

0 commit comments

Comments
 (0)