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

Running an empty RawQuery causes a panic #560

Closed
Tracked by #770
aeneasr opened this issue Jun 9, 2020 · 1 comment · Fixed by #786
Closed
Tracked by #770

Running an empty RawQuery causes a panic #560

aeneasr opened this issue Jun 9, 2020 · 1 comment · Fixed by #786
Assignees
Labels
bug Something isn't working s: fixed was fixed or solution offered
Milestone

Comments

@aeneasr
Copy link
Member

aeneasr commented Jun 9, 2020

Description

Running an empty RawQuery causes a panic.

Steps to Reproduce the Problem

sqlite, _ := pop.NewConnection(&pop.ConnectionDetails{
	URL: "sqlite3://" + filepath.Join(os.TempDir(), x.NewUUID().String()) + ".sql?mode=memory&_fk=true",
})
_ = sqlite.Open()
sqlite.RawQuery("").Exec()

Expected Behavior

No panic.

Actual Behavior

A panic happens:

% go test -tags sqlite .
--- FAIL: TestMigrations (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x46c74f2]

goroutine 10 [running]:
testing.tRunner.func1.1(0x4d86060, 0x5973aa0)
        /usr/local/Cellar/go/1.14.3/libexec/src/testing/testing.go:940 +0x2f5
testing.tRunner.func1(0xc0001c58c0)
        /usr/local/Cellar/go/1.14.3/libexec/src/testing/testing.go:943 +0x3f9
panic(0x4d86060, 0x5973aa0)
        /usr/local/Cellar/go/1.14.3/libexec/src/runtime/panic.go:969 +0x166
github.com/gobuffalo/pop/v5.(*Model).TableName(0x0, 0x0, 0x0)
        /Users/foobar/go/src/github.com/gobuffalo/pop/model.go:79 +0x52
github.com/gobuffalo/pop/v5.(*sqlBuilder).buildColumns(0xc0001fb868, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        /Users/foobar/go/src/github.com/gobuffalo/pop/sql_builder.go:218 +0x65
github.com/gobuffalo/pop/v5.(*sqlBuilder).buildSelectSQL(0xc0001fb868, 0x0, 0x0)
        /Users/foobar/go/src/github.com/gobuffalo/pop/sql_builder.go:102 +0x40
github.com/gobuffalo/pop/v5.(*sqlBuilder).compile(0xc0001fb868)
        /Users/foobar/go/src/github.com/gobuffalo/pop/sql_builder.go:87 +0x369
github.com/gobuffalo/pop/v5.(*sqlBuilder).String(...)
        /Users/foobar/go/src/github.com/gobuffalo/pop/sql_builder.go:57
github.com/gobuffalo/pop/v5.Query.ToSQL(0xc0000333b0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /Users/foobar/go/src/github.com/gobuffalo/pop/query.go:206 +0x1db
github.com/gobuffalo/pop/v5.(*Query).Exec.func1(0xbfaffeb74d0bc090, 0xcc6278)
        /Users/foobar/go/src/github.com/gobuffalo/pop/executors.go:25 +0x91
github.com/gobuffalo/pop/v5.(*Connection).timeFunc(0xc0007a4900, 0x4f07ee0, 0x4, 0xc000079cd0, 0x30, 0x4ded6e0)
        /Users/foobar/go/src/github.com/gobuffalo/pop/connection.go:231 +0x50
github.com/gobuffalo/pop/v5.(*Query).Exec(0xc000079e70, 0xc0000333b0, 0x0)
        /Users/foobar/go/src/github.com/gobuffalo/pop/executors.go:24 +0x6a
github.com/ory/kratos/persistence/sql/migratest.TestMigrations(0xc0001c58c0)
        /Users/foobar/go/src/github.com/ory/kratos/persistence/sql/migratest/migration_test.go:74 +0x2f7
testing.tRunner(0xc0001c58c0, 0x4f7c148)
        /usr/local/Cellar/go/1.14.3/libexec/src/testing/testing.go:991 +0xdc
created by testing.(*T).Run
        /usr/local/Cellar/go/1.14.3/libexec/src/testing/testing.go:1042 +0x357
FAIL    github.com/ory/kratos/persistence/sql/migratest 0.429s

Info

github.com/gobuffalo/pop/v5 v5.1.3
@stanislas-m stanislas-m added the bug Something isn't working label Jun 20, 2020
@sio4 sio4 added this to the v6.0.7 milestone Sep 20, 2022
@sio4 sio4 added the s: triage Some tests need to be run to confirm the issue label Sep 20, 2022
@sio4 sio4 mentioned this issue Sep 20, 2022
30 tasks
@sio4 sio4 self-assigned this Sep 25, 2022
@sio4
Copy link
Member

sio4 commented Sep 25, 2022

This situation is almost the same as executing an empty Query.

github.com/gobuffalo/pop/v5.(*Model).TableName(0x0, 0x0, 0x0)
        /Users/foobar/go/src/github.com/gobuffalo/pop/model.go:79 +0x52

Even though the panic point is in Model,

github.com/gobuffalo/pop/v5.(*sqlBuilder).buildColumns(0xc0001fb868, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        /Users/foobar/go/src/github.com/gobuffalo/pop/sql_builder.go:218 +0x65
github.com/gobuffalo/pop/v5.(*sqlBuilder).buildSelectSQL(0xc0001fb868, 0x0, 0x0)
        /Users/foobar/go/src/github.com/gobuffalo/pop/sql_builder.go:102 +0x40
github.com/gobuffalo/pop/v5.(*sqlBuilder).compile(0xc0001fb868)
        /Users/foobar/go/src/github.com/gobuffalo/pop/sql_builder.go:87 +0x369
github.com/gobuffalo/pop/v5.(*sqlBuilder).String(...)
        /Users/foobar/go/src/github.com/gobuffalo/pop/sql_builder.go:57

within a call chain from buildSelectSQL() called by the empty sqlBuilder for the empty Query,

github.com/gobuffalo/pop/v5.Query.ToSQL(0xc0000333b0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /Users/foobar/go/src/github.com/gobuffalo/pop/query.go:206 +0x1db
github.com/gobuffalo/pop/v5.(*Query).Exec.func1(0xbfaffeb74d0bc090, 0xcc6278)
        /Users/foobar/go/src/github.com/gobuffalo/pop/executors.go:25 +0x91
github.com/gobuffalo/pop/v5.(*Connection).timeFunc(0xc0007a4900, 0x4f07ee0, 0x4, 0xc000079cd0, 0x30, 0x4ded6e0)
        /Users/foobar/go/src/github.com/gobuffalo/pop/connection.go:231 +0x50
github.com/gobuffalo/pop/v5.(*Query).Exec(0xc000079e70, 0xc0000333b0, 0x0)
        /Users/foobar/go/src/github.com/gobuffalo/pop/executors.go:24 +0x6a

executing the Exec() on an empty Query is problematic in the first place.

Filing a PR.

@sio4 sio4 closed this as completed in #786 Sep 25, 2022
@sio4 sio4 added s: fixed was fixed or solution offered and removed s: triage Some tests need to be run to confirm the issue labels Sep 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working s: fixed was fixed or solution offered
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants