-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Hello, I encounter a segmentation fault when input file contains both block and object. Here is a simple example to reproduce the issue:
include {
path = find_in_parent_folders()
}
inputs = {
id = "123"
}
package main
import (
"go.mercari.io/hcledit"
)
func main() {
editor, _ := hcledit.ReadFile("config.hcl")
key := "inputs.id"
editor.Read(key)
}
Error message:
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1021ee128]
goroutine 1 [running]:
go.mercari.io/hcledit/internal/ast.ReplaceBodyTokens(0x140000b89d8, {0x140000a2400, 0x6}, {0x140000fa320, 0xc, 0x1?})
/Users/user/.asdf/installs/golang/1.21.0/packages/pkg/mod/go.mercari.io/[email protected]/internal/ast/ast.go:31 +0x1e8
go.mercari.io/hcledit/internal/walker.(*Walker).walkAttribute(0x14000163ec8, 0x140000b89d8, {0x140000d02e0, 0x2, 0x2}, 0x0, {0x102414400, 0x0, 0x0})
/Users/user/.asdf/installs/golang/1.21.0/packages/pkg/mod/go.mercari.io/[email protected]/internal/walker/walker.go:81 +0x984
go.mercari.io/hcledit/internal/walker.(*Walker).Walk(0x1021f4210?, 0x49?, {0x140000d02e0, 0x2, 0x2}, 0x2a?, {0x102414400, 0x0, 0x0})
/Users/user/.asdf/installs/golang/1.21.0/packages/pkg/mod/go.mercari.io/[email protected]/internal/walker/walker.go:26 +0x40
go.mercari.io/hcledit.(*HCLEditor).Read(0x14000134c60, {0x1021f4210, 0x9}, {0x0, 0x0, 0x140000021a0?})
/Users/user/.asdf/installs/golang/1.21.0/packages/pkg/mod/go.mercari.io/[email protected]/hcledit.go:102 +0x16c
main.main()
/Users/user/sites/golang/hclp/main_backup.go:12 +0x44
exit status 2
What I also noticed:
- if I remove the block and leave only object (or vice versa), it works fine
- the program does not panic if the attribute is not existing in the
input
object (for example, searchinginput.whatever
in this case). It does not find the key, but does not crash.
Thank you!
ryan-ph
Metadata
Metadata
Assignees
Labels
No labels