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

Missing closing brace/bracket causes segfault #932

Closed
forivall opened this issue Sep 8, 2021 · 1 comment
Closed

Missing closing brace/bracket causes segfault #932

forivall opened this issue Sep 8, 2021 · 1 comment
Labels

Comments

@forivall
Copy link

forivall commented Sep 8, 2021

Describe the bug
Most expressions that miss the closing brace (}) or bracket (]) will cause a segfault. Some expressions that miss the closing parenthesis ()) evaluate successfully (although jq errors on these expressions), but specially crafted expressions are able to hit the same segfault.

Version of yq: 4.12.1
Operating system: mac
Installed via: binary homebrew

Command
The command you ran:

yq e --null-input '({"foo": ["bar"}'
yq e --null-input '{"foo": "bar"'
yq e --null-input '[(.bar |= "baz")'
yq e --null-input '({"foo": ("bar"}'

Actual behavior

(some values vary from expression to expression, but are consistent; i'm guessing those are offsets or something in the input. However, the stack is the same for all of the commands)

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x125f3e6]

goroutine 1 [running]:
github.com/mikefarah/yq/v4/pkg/yqlib.(*Operation).toString(0x0, 0xc000230930, 0x1)
	github.com/mikefarah/yq/v4/pkg/yqlib/lib.go:152 +0x26
github.com/mikefarah/yq/v4/pkg/yqlib.(*expressionParserImpl).createExpressionTree(0xc000266820, 0xc00025f840, 0x6, 0x8, 0xc00025f840, 0x6, 0x8)
	github.com/mikefarah/yq/v4/pkg/yqlib/expression_parser.go:49 +0xe5
github.com/mikefarah/yq/v4/pkg/yqlib.(*expressionParserImpl).ParseExpression(0xc000266820, 0x7ffeefbff3ca, 0x10, 0xc000273af8, 0x100f518, 0x20)
	github.com/mikefarah/yq/v4/pkg/yqlib/expression_parser.go:37 +0xf4
github.com/mikefarah/yq/v4/pkg/yqlib.(*streamEvaluator).EvaluateNew(0xc000273d50, 0x7ffeefbff3ca, 0x10, 0x13f3d50, 0xc0000b5d50, 0x0, 0x0, 0x78, 0x132a620)
	github.com/mikefarah/yq/v4/pkg/yqlib/stream_evaluator.go:31 +0x63
github.com/mikefarah/yq/v4/cmd.evaluateSequence(0xc0000b9180, 0xc00007e420, 0x1, 0x2, 0x0, 0x0)
	github.com/mikefarah/yq/v4/cmd/evalute_sequence_command.go:143 +0x816
github.com/spf13/cobra.(*Command).execute(0xc0000b9180, 0xc00007e400, 0x2, 0x2, 0xc0000b9180, 0xc00007e400)
	github.com/spf13/cobra@v1.1.3/command.go:852 +0x472
github.com/spf13/cobra.(*Command).ExecuteC(0xc0000b8f00, 0x0, 0xffffffff, 0xc0000220b8)
	github.com/spf13/cobra@v1.1.3/command.go:960 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/cobra@v1.1.3/command.go:897
main.main()
	github.com/mikefarah/yq/v4/yq.go:11 +0x2a

Expected behavior

Error: Bad path expression, expected close collect brackets at end of expression

Additional context

$ yq e --null-input '({"foo": ["bar"]}'
foo:
  - bar

$ yq e --null-input '({"foo": "bar"}'
foo: bar

evaluates successfully.

jq equivalents ``` $ jq --null-input '([{"foo": ["bar"]]}' jq: error: syntax error, unexpected INVALID_CHARACTER, expecting '}' (Unix shell quoting issues?) at , line 1: ([{"foo": ["bar"]]}

$ jq --null-input '({"foo": ["bar"}'
jq: error: syntax error, unexpected INVALID_CHARACTER (Unix shell quoting issues?) at , line 1:
({"foo": ["bar"}
jq: 1 compile error

$ jq --null-input '{"foo": "bar"'
jq: error: syntax error, unexpected $end, expecting '}' (Unix shell quoting issues?) at , line 1:
{"foo": "bar"
jq: 1 compile error

$ jq --null-input '[(.bar |= "baz")'
jq: error: syntax error, unexpected $end (Unix shell quoting issues?) at , line 1:
[(.bar |= "baz")
jq: 1 compile error

$ jq --null-input '({"foo": ("bar"}'
jq: error: syntax error, unexpected INVALID_CHARACTER (Unix shell quoting issues?) at , line 1:
({"foo": ("bar"}
jq: 1 compile error

</details>
@mikefarah
Copy link
Owner

Fixed in 4.13.0

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

No branches or pull requests

2 participants