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

\show in SQL shell panics when arg isn't a commit #8727

Closed
milogreg opened this issue Jan 9, 2025 · 2 comments · Fixed by #8730
Closed

\show in SQL shell panics when arg isn't a commit #8727

milogreg opened this issue Jan 9, 2025 · 2 comments · Fixed by #8730
Assignees

Comments

@milogreg
Copy link
Contributor

milogreg commented Jan 9, 2025

Running \show abc in the dolt SQL shell causes a panic. You can replace abc with any string that isn't a commit or a flag.

This panic happens because show's Exec function (implemented in go/cmd/dolt/commands/show.go) is given a nil DoltEnv when called from the SQL shell with handleSlashCommand (implemented in go/cmd/dolt/commands/sql_slash.go). This is fine when the args only contain commits because the DoltEnv isn't used in that case, but if non-commit args are present the nil DoltEnv is dereferenced, causing a panic.

Trace:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x40 pc=0x10283e774]

goroutine 1 [running]:
github.com/dolthub/dolt/go/libraries/doltcore/env.(*DoltEnv).WorkingSet(...)
        /Users/user/Development/dolt/go/libraries/doltcore/env/environment.go:654
github.com/dolthub/dolt/go/libraries/doltcore/env.(*DoltEnv).Roots(0x0, {0x103eb8d08, 0x14001ef9e00})
        /Users/user/Development/dolt/go/libraries/doltcore/env/environment.go:582 +0x64
github.com/dolthub/dolt/go/cmd/dolt/commands.getValueFromRefSpec({0x103eb8d08, 0x14001ef9e00}, 0x0, {0x14002f086d6, 0x3})
        /Users/user/Development/dolt/go/cmd/dolt/commands/show.go:226 +0x54
github.com/dolthub/dolt/go/cmd/dolt/commands.ShowCmd.Exec({}, {0x103eb8d08, 0x14001ef9e00}, {0x102e7b810, 0x4}, {0x14000cc40b0, 0x1, 0x9}, 0x0, {0x103eb8e20, ...})
        /Users/user/Development/dolt/go/cmd/dolt/commands/show.go:193 +0x5d8
github.com/dolthub/dolt/go/cmd/dolt/commands.handleSlashCommand(0x14001ef9e00, {0x103ebe6c0, 0x106cbb3a0}, {0x14002f086d0?, 0x103eb8e20?}, {0x103eb8e20, 0x14001efeea0})
        /Users/user/Development/dolt/go/cmd/dolt/commands/sql_slash.go:80 +0xc4
github.com/dolthub/dolt/go/cmd/dolt/commands.execShell.func3.1({0x103eb89b8, 0x14001efef00}, 0x14001ef9040, 0x14002f06ea0, 0x14000c00010, {0x103eb8e20, 0x14001efeea0}, 0x140006cf600, {0x103ea5db8, 0x140005ff4d0}, ...)
        /Users/user/Development/dolt/go/cmd/dolt/commands/sql.go:790 +0x39c
github.com/dolthub/dolt/go/cmd/dolt/commands.execShell.func3(0x140006cf600?)
        /Users/user/Development/dolt/go/cmd/dolt/commands/sql.go:822 +0x2ec
github.com/dolthub/ishell.handleUninterpretedInput(0x140006cf600, {0x14002f086d0, 0x9})
        /Users/user/go/pkg/mod/github.com/dolthub/ishell@v0.0.0-20240701202509-2b217167d718/ishell.go:299 +0x1e4
github.com/dolthub/ishell.(*Shell).run(0x140006cf600)
        /Users/user/go/pkg/mod/github.com/dolthub/ishell@v0.0.0-20240701202509-2b217167d718/ishell.go:252 +0x280
github.com/dolthub/ishell.(*Shell).Run(0x140006cf600)
        /Users/user/go/pkg/mod/github.com/dolthub/ishell@v0.0.0-20240701202509-2b217167d718/ishell.go:146 +0x28
github.com/dolthub/dolt/go/cmd/dolt/commands.execShell(0x14001ef9040, {0x103ea5db8, 0x140005ff4d0}, 0x0, {0x103eb8e20, 0x14001efeea0})
        /Users/user/Development/dolt/go/cmd/dolt/commands/sql.go:832 +0x628
github.com/dolthub/dolt/go/cmd/dolt/commands.SqlCmd.Exec({{0x102e7eb7b?, 0x103cb2a20?}}, {0x103eb89b8, 0x14001efef00}, {0x140012ae260, 0x8}, {0x140001d4010, 0x0, 0x0}, 0x14002167cb0, ...)
        /Users/user/Development/dolt/go/cmd/dolt/commands/sql.go:263 +0xc8c
github.com/dolthub/dolt/go/cmd/dolt/cli.SubCommandHandler.handleCommand({{0x102e7b5f8, 0x4}, {0x102e9cad5, 0x11}, {0x0, 0x0}, {0x105539380, 0x38, 0x38}, 0x0}, ...)
        /Users/user/Development/dolt/go/cmd/dolt/cli/command.go:246 +0x4d0
github.com/dolthub/dolt/go/cmd/dolt/cli.SubCommandHandler.Exec({{0x102e7b5f8, 0x4}, {0x102e9cad5, 0x11}, {0x0, 0x0}, {0x105539380, 0x38, 0x38}, 0x0}, ...)
        /Users/user/Development/dolt/go/cmd/dolt/cli/command.go:195 +0x234
main.runMain()
        /Users/user/Development/dolt/go/cmd/dolt/dolt.go:588 +0x2750
main.main()
        /Users/user/Development/dolt/go/cmd/dolt/dolt.go:252 +0x1c
@macneale4
Copy link
Contributor

Thanks for the bug report. Definitely shouldn't do that!

@macneale4
Copy link
Contributor

The panic you reported is fixed, and will go out with the next release. Thanks again for the bug report!

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

Successfully merging a pull request may close this issue.

3 participants