Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation violation when file contains a block and an object #98

Open
dmitry-g opened this issue Dec 8, 2023 · 1 comment
Open

Comments

@dmitry-g
Copy link

dmitry-g commented Dec 8, 2023

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, searching input.whatever in this case). It does not find the key, but does not crash.

Thank you!

@AshkanYarmoradi
Copy link

Any Update on this topic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants