From 8458102b3bc3a56f1ae6354bbf57ad3737da8212 Mon Sep 17 00:00:00 2001 From: James Cor Date: Wed, 4 Dec 2024 12:19:25 -0800 Subject: [PATCH 1/7] prevent most types from being as of clauses --- enginetest/queries/queries.go | 4 ++++ sql/planbuilder/show.go | 1 + 2 files changed, 5 insertions(+) diff --git a/enginetest/queries/queries.go b/enginetest/queries/queries.go index 32db69e1dc..a6c321dec0 100644 --- a/enginetest/queries/queries.go +++ b/enginetest/queries/queries.go @@ -10751,6 +10751,10 @@ var ErrorQueries = []QueryErrorTest{ Query: "SELECT i FROM myhistorytable AS OF MAX(i)", ExpectedErr: sql.ErrInvalidAsOfExpression, }, + { + Query: "SELECT i FROM myhistorytable AS OF (SELECT 1)", + ExpectedErrStr: "invalid AS OF expression type", + }, { Query: "SELECT pk FROM one_pk WHERE pk > ?", ExpectedErr: sql.ErrUnboundPreparedStatementVariable, diff --git a/sql/planbuilder/show.go b/sql/planbuilder/show.go index dfcae8e063..63b645272e 100644 --- a/sql/planbuilder/show.go +++ b/sql/planbuilder/show.go @@ -616,6 +616,7 @@ func (b *Builder) buildAsOfExpr(inScope *scope, time ast.Expr) sql.Expression { b.handleErr(err) } default: + b.handleErr(fmt.Errorf("invalid AS OF expression type")) } return b.buildScalar(b.newScope(), time) } From a645c48171bd3764df6ba52d0e4f3beafcb5ebd6 Mon Sep 17 00:00:00 2001 From: James Cor Date: Wed, 4 Dec 2024 12:33:07 -0800 Subject: [PATCH 2/7] subqueries specifically --- sql/planbuilder/show.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/planbuilder/show.go b/sql/planbuilder/show.go index 63b645272e..6376e05a39 100644 --- a/sql/planbuilder/show.go +++ b/sql/planbuilder/show.go @@ -615,8 +615,9 @@ func (b *Builder) buildAsOfExpr(inScope *scope, time ast.Expr) sql.Expression { err := sql.ErrInvalidAsOfExpression.New(v) b.handleErr(err) } - default: + case *ast.Subquery: b.handleErr(fmt.Errorf("invalid AS OF expression type")) + default: } return b.buildScalar(b.newScope(), time) } From 5c8ce7ab542a66d8ab8cda555828d8bd169341c9 Mon Sep 17 00:00:00 2001 From: James Cor Date: Wed, 4 Dec 2024 12:50:20 -0800 Subject: [PATCH 3/7] block all; whitelist convert --- enginetest/memory_engine_test.go | 14 +++++++++++--- sql/planbuilder/show.go | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/enginetest/memory_engine_test.go b/enginetest/memory_engine_test.go index 315c1b243b..188126b487 100644 --- a/enginetest/memory_engine_test.go +++ b/enginetest/memory_engine_test.go @@ -197,12 +197,20 @@ func TestSingleQueryPrepared(t *testing.T) { // Convenience test for debugging a single query. Unskip and set to the desired query. func TestSingleScript(t *testing.T) { - t.Skip() + //t.Skip() var scripts = []queries.ScriptTest{ { Name: "test script", - SetUpScript: []string{}, - Assertions: []queries.ScriptTestAssertion{}, + SetUpScript: []string{ + "create table t (i tinytext unique);", + "insert into t values ('hello');", + }, + Assertions: []queries.ScriptTestAssertion{ + { + Query: "insert into t values ('hello');", + ExpectedErrStr: "asdf", + }, + }, }, } diff --git a/sql/planbuilder/show.go b/sql/planbuilder/show.go index 6376e05a39..f82b689445 100644 --- a/sql/planbuilder/show.go +++ b/sql/planbuilder/show.go @@ -615,9 +615,9 @@ func (b *Builder) buildAsOfExpr(inScope *scope, time ast.Expr) sql.Expression { err := sql.ErrInvalidAsOfExpression.New(v) b.handleErr(err) } - case *ast.Subquery: - b.handleErr(fmt.Errorf("invalid AS OF expression type")) + case *ast.ConvertExpr: default: + b.handleErr(fmt.Errorf("invalid AS OF expression type")) } return b.buildScalar(b.newScope(), time) } From 91d212d6cbf942071f21ca40c4e424689f8a8588 Mon Sep 17 00:00:00 2001 From: jycor Date: Wed, 4 Dec 2024 20:52:11 +0000 Subject: [PATCH 4/7] [ga-format-pr] Run ./format_repo.sh to fix formatting --- enginetest/memory_engine_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/enginetest/memory_engine_test.go b/enginetest/memory_engine_test.go index 188126b487..0bb366be9e 100644 --- a/enginetest/memory_engine_test.go +++ b/enginetest/memory_engine_test.go @@ -200,14 +200,14 @@ func TestSingleScript(t *testing.T) { //t.Skip() var scripts = []queries.ScriptTest{ { - Name: "test script", + Name: "test script", SetUpScript: []string{ "create table t (i tinytext unique);", "insert into t values ('hello');", }, - Assertions: []queries.ScriptTestAssertion{ + Assertions: []queries.ScriptTestAssertion{ { - Query: "insert into t values ('hello');", + Query: "insert into t values ('hello');", ExpectedErrStr: "asdf", }, }, From bafc32b5ff10587bc97bc6ce6bd0a8e846c8aae8 Mon Sep 17 00:00:00 2001 From: James Cor Date: Wed, 4 Dec 2024 12:56:53 -0800 Subject: [PATCH 5/7] error --- sql/plan/subquery.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sql/plan/subquery.go b/sql/plan/subquery.go index 2d0d5f7147..cbb5880039 100644 --- a/sql/plan/subquery.go +++ b/sql/plan/subquery.go @@ -349,6 +349,10 @@ func (s *Subquery) evalMultiple(ctx *sql.Context, row sql.Row) ([]interface{}, e return nil, err } + if s.b == nil { + return nil, fmt.Errorf("attempted to evaluate uninitialized subquery") + } + iter, err := s.b.Build(ctx, q, row) if err != nil { return nil, err @@ -434,6 +438,10 @@ func (s *Subquery) HasResultRow(ctx *sql.Context, row sql.Row) (bool, error) { return false, err } + if s.b == nil { + return false, fmt.Errorf("attempted to evaluate uninitialized subquery") + } + iter, err := s.b.Build(ctx, q, row) if err != nil { return false, err From 44e8f959044872b97893a7d20fcb970962a10335 Mon Sep 17 00:00:00 2001 From: James Cor Date: Wed, 4 Dec 2024 12:57:40 -0800 Subject: [PATCH 6/7] revert --- enginetest/memory_engine_test.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/enginetest/memory_engine_test.go b/enginetest/memory_engine_test.go index 0bb366be9e..315c1b243b 100644 --- a/enginetest/memory_engine_test.go +++ b/enginetest/memory_engine_test.go @@ -197,20 +197,12 @@ func TestSingleQueryPrepared(t *testing.T) { // Convenience test for debugging a single query. Unskip and set to the desired query. func TestSingleScript(t *testing.T) { - //t.Skip() + t.Skip() var scripts = []queries.ScriptTest{ { - Name: "test script", - SetUpScript: []string{ - "create table t (i tinytext unique);", - "insert into t values ('hello');", - }, - Assertions: []queries.ScriptTestAssertion{ - { - Query: "insert into t values ('hello');", - ExpectedErrStr: "asdf", - }, - }, + Name: "test script", + SetUpScript: []string{}, + Assertions: []queries.ScriptTestAssertion{}, }, } From 360f89e00f28710dcf6aa684386b34f5275cda0b Mon Sep 17 00:00:00 2001 From: James Cor Date: Wed, 4 Dec 2024 13:29:09 -0800 Subject: [PATCH 7/7] allow injected --- sql/planbuilder/show.go | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/planbuilder/show.go b/sql/planbuilder/show.go index f82b689445..2a04a0cf49 100644 --- a/sql/planbuilder/show.go +++ b/sql/planbuilder/show.go @@ -616,6 +616,7 @@ func (b *Builder) buildAsOfExpr(inScope *scope, time ast.Expr) sql.Expression { b.handleErr(err) } case *ast.ConvertExpr: + case ast.InjectedExpr: default: b.handleErr(fmt.Errorf("invalid AS OF expression type")) }