hcl: RelTraversalForExpr must copy traversal before modifying it
The traversal returned from AbsTraversalForExpr may, for some expression types, be referring to the same backing array as one stored inside the node itself, and so previously this function may have inadvertently corrupted the data associated with an AST node.
This commit is contained in:
parent
dac4796ca1
commit
253da47fd6
@ -52,11 +52,14 @@ func AbsTraversalForExpr(expr Expression) (Traversal, Diagnostics) {
|
||||
func RelTraversalForExpr(expr Expression) (Traversal, Diagnostics) {
|
||||
traversal, diags := AbsTraversalForExpr(expr)
|
||||
if len(traversal) > 0 {
|
||||
ret := make(Traversal, len(traversal))
|
||||
copy(ret, traversal)
|
||||
root := traversal[0].(TraverseRoot)
|
||||
traversal[0] = TraverseAttr{
|
||||
ret[0] = TraverseAttr{
|
||||
Name: root.Name,
|
||||
SrcRange: root.SrcRange,
|
||||
}
|
||||
return ret, diags
|
||||
}
|
||||
return traversal, diags
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user