Skip to content

Commit

Permalink
Initialize field before use (#359)
Browse files Browse the repository at this point in the history
The `parseField` function was not initializing `v` on an error case, which could led to subsequent code trying to use an uninitialized pointer and causing a panic.
  • Loading branch information
lblackstone authored Jul 19, 2024
1 parent aab4e51 commit c61d9d3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ast/environment.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023, Pulumi Corporation.
// Copyright 2024, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -293,6 +293,7 @@ func parseField(name string, dest reflect.Value, node syntax.Node) syntax.Diagno
xv := reflect.ValueOf(x)
if !xv.Type().AssignableTo(dest.Type()) {
diags.Extend(exprFieldTypeMismatchError(name, dest.Interface(), x))
v = reflect.New(dest.Type().Elem())
} else {
v = xv
}
Expand Down

0 comments on commit c61d9d3

Please sign in to comment.