Changeset: 838a69a96c86 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=838a69a96c86 Removed Files: sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.sql sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.sql sql/test/miscellaneous/Tests/simple_selects.sql Modified Files: sql/backends/monet5/rel_bin.c sql/backends/monet5/sql_cat.c sql/backends/monet5/sql_gencode.c sql/backends/monet5/sql_scenario.c sql/server/rel_select.c sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.test sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.test sql/test/miscellaneous/Tests/simple_selects.test Branch: default Log Message:
Merged with Oct2020 diffs (truncated from 324 to 300 lines): diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c --- a/sql/backends/monet5/rel_bin.c +++ b/sql/backends/monet5/rel_bin.c @@ -2740,7 +2740,7 @@ rel2bin_semijoin(backend *be, sql_rel *r const char *rnme = table_name(sql->sa, c); const char *nme = column_name(sql->sa, c); - if (l_is_base && nme[0] == '%' && strcmp(nme, TID) == 0) + if (semijoin_only && l_is_base && nme[0] == '%' && strcmp(nme, TID) == 0) s = join; else s = stmt_project(be, join, column(be, c)); diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c --- a/sql/backends/monet5/sql_cat.c +++ b/sql/backends/monet5/sql_cat.c @@ -788,12 +788,13 @@ create_func(mvc *sql, char *sname, char FUNC_TYPE_STR(f->type, F, fn) - (void) fname; (void) fn; if (!(s = mvc_bind_schema(sql, sname))) throw(SQL,"sql.create_func", SQLSTATE(3F000) "CREATE %s: no such schema '%s'", F, sname); if (!mvc_schema_privs(sql, s)) throw(SQL,"sql.create_func", SQLSTATE(42000) "CREATE %s: access denied for %s to schema '%s'", F, get_string_global_var(sql, "current_user"), s->base.name); + if (strlen(fname) >= IDLENGTH) + throw(SQL,"sql.create_func", SQLSTATE(42000) "CREATE %s: name '%s' too large for the backend", F, fname); nf = mvc_create_func(sql, NULL, s, f->base.name, f->ops, f->res, f->type, f->lang, f->mod, f->imp, f->query, f->varres, f->vararg, f->system); assert(nf); switch (nf->lang) { diff --git a/sql/backends/monet5/sql_gencode.c b/sql/backends/monet5/sql_gencode.c --- a/sql/backends/monet5/sql_gencode.c +++ b/sql/backends/monet5/sql_gencode.c @@ -141,6 +141,14 @@ static int int res = 0; str msg = MAL_SUCCEED; + if (strlen(mod) >= IDLENGTH) { + (void) sql_error(m, 02, SQLSTATE(42000) "Module name '%s' too large for the backend", mod); + return -1; + } + if (strlen(name) >= IDLENGTH) { + (void) sql_error(m, 02, SQLSTATE(42000) "Function name '%s' too large for the backend", name); + return -1; + } backup = c->curprg; curPrg = c->curprg = newFunction(putName(mod), putName(name), FUNCTIONsymbol); if( curPrg == NULL) { @@ -181,7 +189,10 @@ static int sql_error(m, 001, SQLSTATE(HY013) MAL_MALLOC_FAIL); return -1; } - varid = newVariable(curBlk, buf, strlen(buf), type); + if ((varid = newVariable(curBlk, buf, strlen(buf), type)) < 0) { + sql_error(m, 003, SQLSTATE(42000) "Internal error while compiling statement: variable id too long"); + return -1; + } curInstr = pushArgument(curBlk, curInstr, varid); setVarType(curBlk, varid, type); } @@ -209,7 +220,10 @@ static int sql_error(m, 001, SQLSTATE(HY013) MAL_MALLOC_FAIL); return -1; } - varid = newVariable(curBlk, (char *)buf, strlen(buf), type); + if ((varid = newVariable(curBlk, (char *)buf, strlen(buf), type)) < 0) { + sql_error(m, 003, SQLSTATE(42000) "Internal error while compiling statement: variable id too long"); + return -1; + } curInstr = pushArgument(curBlk, curInstr, varid); setVarType(curBlk, varid, type); } @@ -306,6 +320,14 @@ static int sql_error(m, 003, SQLSTATE(42000) "Missing property on the input relation"); return -1; } + if (strlen(mod) >= IDLENGTH) { + sql_error(m, 003, SQLSTATE(42000) "Module name '%s' too large for the backend", mod); + return -1; + } + if (strlen(name) >= IDLENGTH) { + sql_error(m, 003, SQLSTATE(42000) "Function name '%s' too large for the backend", name); + return -1; + } lname = GDKstrdup(name); if (lname == NULL) { @@ -367,7 +389,11 @@ static int return -1; } stpcpy(stpcpy(buf, "A"), nme); - varid = newVariable(curBlk, buf,strlen(buf), type); + if ((varid = newVariable(curBlk, buf,strlen(buf), type)) < 0) { + GDKfree(lname); + sql_error(m, 003, SQLSTATE(42000) "Internal error while compiling statement: variable id too long"); + return -1; + } curInstr = pushArgument(curBlk, curInstr, varid); setVarType(curBlk, varid, type); } @@ -786,10 +812,12 @@ backend_dumpproc(backend *be, Client c, argc += list_length(m->params); if (argc < MAXARG) argc = MAXARG; - if (cq) + if (cq) { + assert(strlen(cq->name) < IDLENGTH); c->curprg = newFunctionArgs(userRef, putName(cq->name), FUNCTIONsymbol, argc); - else + } else { c->curprg = newFunctionArgs(userRef, "tmp", FUNCTIONsymbol, argc); + } if (c->curprg == NULL) { sql_error(m, 001, SQLSTATE(HY013) MAL_MALLOC_FAIL); return NULL; @@ -817,7 +845,10 @@ backend_dumpproc(backend *be, Client c, } type = tpe->localtype; snprintf(arg, IDLENGTH, "A%d", argc); - varid = newVariable(mb, arg,strlen(arg), type); + if ((varid = newVariable(mb, arg,strlen(arg), type)) < 0) { + sql_error(m, 003, SQLSTATE(42000) "Internal error while compiling statement: variable id too long"); + goto cleanup; + } curInstr = pushArgument(mb, curInstr, varid); if (c->curprg == NULL) { sql_error(m, 003, SQLSTATE(HY013) MAL_MALLOC_FAIL); @@ -1121,6 +1152,10 @@ backend_create_sql_func(backend *be, sql sql_rel *r; str msg = MAL_SUCCEED; + if (strlen(f->base.name) >= IDLENGTH) { + (void) sql_error(m, 02, SQLSTATE(42000) "Function name '%s' too large for the backend", f->base.name); + return -1; + } /* nothing to do for internal and ready (not recompiling) functions, besides finding respective MAL implementation */ if (!f->sql && (f->lang == FUNC_LANG_INT || f->lang == FUNC_LANG_MAL)) { if (f->lang == FUNC_LANG_MAL && !f->imp && !mal_function_find_implementation_address(m, f)) @@ -1189,7 +1224,10 @@ backend_create_sql_func(backend *be, sql char buf[IDLENGTH]; (void) snprintf(buf, IDLENGTH, "A%d", argc); - varid = newVariable(curBlk, buf, strlen(buf), type); + if ((varid = newVariable(curBlk, buf, strlen(buf), type)) < 0) { + sql_error(m, 003, SQLSTATE(42000) "Internal error while compiling statement: variable id too long"); + goto cleanup; + } curInstr = pushArgument(curBlk, curInstr, varid); setVarType(curBlk, varid, type); } @@ -1216,7 +1254,10 @@ backend_create_sql_func(backend *be, sql sql_error(m, 001, SQLSTATE(HY013) MAL_MALLOC_FAIL); goto cleanup; } - varid = newVariable(curBlk, buf, strlen(buf), type); + if ((varid = newVariable(curBlk, buf, strlen(buf), type)) < 0) { + sql_error(m, 003, SQLSTATE(42000) "Internal error while compiling statement: variable id too long"); + goto cleanup; + } curInstr = pushArgument(curBlk, curInstr, varid); setVarType(curBlk, varid, type); } diff --git a/sql/backends/monet5/sql_scenario.c b/sql/backends/monet5/sql_scenario.c --- a/sql/backends/monet5/sql_scenario.c +++ b/sql/backends/monet5/sql_scenario.c @@ -1150,6 +1150,7 @@ SQLparser(Client c) m->params = NULL; /* register name in the namespace */ if (be->q) { + assert(strlen(be->q->name) < IDLENGTH); be->q->name = putName(be->q->name); if (!be->q->name) { err = 1; diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c --- a/sql/server/rel_select.c +++ b/sql/server/rel_select.c @@ -5229,7 +5229,9 @@ rel_table_exp(sql_query *query, sql_rel } } } - + list *distinct_exps = list_distinct(exps, (fcmp) exp_equal, (fdup) NULL); + if (list_length(distinct_exps) != list_length(exps)) + return sql_error(sql, 02, SQLSTATE(42000) "Duplicate column names in table%s%s%s projection list", tname ? " '" : "", tname ? tname : "", tname ? "'" : ""); return exps; } if (!tname) diff --git a/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.test b/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.test --- a/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.test +++ b/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.test @@ -10,13 +10,28 @@ insert into test (x, y) VALUES (1, 2) query IIII rowsort SELECT * FROM ( - SELECT a1.x, a1.y, a2.x, a2.y + SELECT a1.x, a1.y, a2.x as w, a2.y as z FROM ( SELECT * FROM test) AS a1 JOIN ( SELECT * FROM test) AS a2 ON a1.x = a2.x ) AS t ---- -16 values hashing to 3eca16e9cfb8a195b29ff52eed7ee064 +1 +1 +1 +1 +1 +1 +1 +2 +1 +2 +1 +1 +1 +2 +1 +2 query IIII rowsort SELECT * @@ -27,7 +42,22 @@ FROM ( ON a1.x = a2.x ) AS t ---- -16 values hashing to 3eca16e9cfb8a195b29ff52eed7ee064 +1 +1 +1 +1 +1 +1 +1 +2 +1 +2 +1 +1 +1 +2 +1 +2 statement ok drop table test diff --git a/sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.test b/sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.test --- a/sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.test +++ b/sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.test @@ -5,13 +5,13 @@ 1 2 query II rowsort -select a.* from (select 1 as T, 2 as T) a +select a.* from (select 1 as T, 2 as U) a ---- 1 2 query II rowsort -with wa as (select 1 as T, 2 as T) select wa.* from wa +with wa as (select 1 as T, 2 as U) select wa.* from wa ---- 1 2 diff --git a/sql/test/miscellaneous/Tests/simple_selects.test b/sql/test/miscellaneous/Tests/simple_selects.test --- a/sql/test/miscellaneous/Tests/simple_selects.test +++ b/sql/test/miscellaneous/Tests/simple_selects.test @@ -601,11 +601,14 @@ select * from myv limit 1 statement ok rollback -query II rowsort +statement error select * from (select 1 as c0, 2 as c0) as sub ----- -1 -2 + +statement error +select *,* from (select 1 as c0, 2 as c0) as sub + +statement error +select * from (select 1 as c0, max(k) as c0 from (select 2, 3) tst(k, name) group by name) as sub query T rowsort select cast(interval '3' second as clob) @@ -757,28 +760,28 @@ select "😀"() 1 statement ok +rollback + +statement ok CREATE FUNCTION ups() RETURNS INT BEGIN DECLARE "nononononononononononononononononononononononononononononononono" int; RETURN "nononononononononononononononononononononononononononononononono"; -END +END; -- error for now _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list