Changeset: 5295c7d58eb9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5295c7d58eb9
Branch: Oct2020
Log Message:

merged


diffs (truncated from 354 to 300 lines):

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
@@ -789,12 +789,13 @@ create_func(mvc *sql, char *sname, char 
 
        FUNC_TYPE_STR(f->type)
 
-       (void) fname;
        (void) fn;
        if (sname && !(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, sqlvar_get_string(find_global_var(sql, 
mvc_bind_schema(sql, "sys"), "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
@@ -143,6 +143,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) {
@@ -184,7 +192,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);
                        setVarUDFtype(curBlk, varid);
@@ -213,7 +224,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);
                        setVarUDFtype(curBlk, varid);
@@ -311,6 +325,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) {
@@ -373,7 +395,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);
                        setVarUDFtype(curBlk, varid);
@@ -789,10 +815,12 @@ backend_dumpproc(backend *be, Client c, 
        int argc = 0, res, added_to_cache = 0;
 
        backup = c->curprg;
-       if (cq)
+       if (cq) {
+               assert(strlen(cq->name) < IDLENGTH);
                c->curprg = newFunction(userRef, putName(cq->name), 
FUNCTIONsymbol);
-       else
+       } else {
                c->curprg = newFunction(userRef, "tmp", FUNCTIONsymbol);
+       }
        if (c->curprg == NULL) {
                sql_error(m, 001, SQLSTATE(HY013) MAL_MALLOC_FAIL);
                return NULL;
@@ -820,7 +848,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);
@@ -1125,6 +1156,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))
@@ -1194,7 +1229,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);
                        setVarUDFtype(curBlk, varid);
@@ -1222,7 +1260,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);
                        setVarUDFtype(curBlk, varid);
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
@@ -1135,6 +1135,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
@@ -5258,7 +5258,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.sql 
b/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.sql
--- a/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.sql
+++ b/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.sql
@@ -5,7 +5,7 @@ insert into test (x, y) VALUES (1, 2);
 
 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
diff --git 
a/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.stable.out 
b/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.stable.out
--- a/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.stable.out
+++ b/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.stable.out
@@ -37,7 +37,7 @@ stdout of test 'duplicate_column_name.Bu
 #              ON a1.x = a2.x
 #      ) AS t;
 % sys.t,       sys.t,  sys.t,  sys.t # table_name
-% x,   y,      x,      y # name
+% x,   y,      w,      z # name
 % int, int,    int,    int # type
 % 1,   1,      1,      1 # length
 [ 1,   1,      1,      1       ]
diff --git 
a/sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.sql 
b/sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.sql
--- 
a/sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.sql
+++ 
b/sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.sql
@@ -1,6 +1,6 @@
 select 1 as T, 2 as T;
-select a.* from (select 1 as T, 2 as T) a;
-with wa as (select 1 as T, 2 as T) select wa.* from wa;
+select a.* from (select 1 as T, 2 as U) a;
+with wa as (select 1 as T, 2 as U) select wa.* from wa;
 
 select 1,2,3 as "L2";
 select a.* from (select 1,2,3 as "L2") a;
diff --git 
a/sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.stable.out
 
b/sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.stable.out
--- 
a/sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.stable.out
+++ 
b/sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.stable.out
@@ -28,15 +28,15 @@ stdout of test 'disallow_duplicate_colum
 % tinyint,     tinyint # type
 % 1,   1 # length
 [ 1,   2       ]
-#select a.* from (select 1 as T, 2 as T) a;
+#select a.* from (select 1 as T, 2 as U) a;
 % .a,  .a # table_name
-% t,   t # name
+% t,   u # name
 % tinyint,     tinyint # type
 % 1,   1 # length
 [ 1,   2       ]
-#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;
 % .wa, .wa # table_name
-% t,   t # name
+% t,   u # name
 % tinyint,     tinyint # type
 % 1,   1 # length
 [ 1,   2       ]
diff --git a/sql/test/miscellaneous/Tests/simple_selects.sql 
b/sql/test/miscellaneous/Tests/simple_selects.sql
--- a/sql/test/miscellaneous/Tests/simple_selects.sql
+++ b/sql/test/miscellaneous/Tests/simple_selects.sql
@@ -199,13 +199,13 @@ select * from myv limit 1;
 rollback;
 
 select * from (select 1 as c0, 2 as c0) as sub;
-       -- 1 2
+       -- error, duplicate column names
 
 select *,* from (select 1 as c0, 2 as c0) as sub;
-       --  1 2 1 2
+       -- error, duplicate column names
 
 select * from (select 1 as c0, max(k) as c0 from (select 2, 3) tst(k, name) 
group by name) as sub;
-       -- 1 2
+       -- error, duplicate column names
 
 select cast(interval '3' second as clob);
        -- 3.000
@@ -273,17 +273,15 @@ start transaction;
 create function "😀"() returns int return 1;
 select "😀"();
        -- 1
+rollback;
+
 CREATE FUNCTION ups() RETURNS INT
 BEGIN
        DECLARE 
"nononononononononononononononononononononononononononononononono" int;
        RETURN 
"nononononononononononononononononononononononononononononononono";
-END;
-select ups();
-       -- NULL
-create function 
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"() returns 
int return 2;
-select "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"();
-       -- 2
-create function "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀"() returns int return 3;
-select "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀"();
-       -- 3
-rollback;
+END;  -- error for now
+select ups();  -- error for now
+create function 
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"() returns 
int return 2;  -- error for now
+select "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"();  
-- error for now
+create function "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀"() returns int return 3;  -- error for now
+select "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀"();  -- error for now
diff --git a/sql/test/miscellaneous/Tests/simple_selects.stable.err 
b/sql/test/miscellaneous/Tests/simple_selects.stable.err
--- a/sql/test/miscellaneous/Tests/simple_selects.stable.err
+++ b/sql/test/miscellaneous/Tests/simple_selects.stable.err
@@ -262,7 +262,19 @@ MAPI  = (monetdb) /var/tmp/mtest-518219/
 QUERY = select cast(92233720368547750 as interval second); --error, overflow 
in conversion for interval second
 ERROR = !types bigint(57,0) and sec_interval(13,0) are not equal
 CODE  = 42000
-MAPI  = (monetdb) /var/tmp/mtest-493793/.s.monetdb.35088
+MAPI  = (monetdb) /var/tmp/mtest-21556/.s.monetdb.36393
+QUERY = select * from (select 1 as c0, 2 as c0) as sub;
+ERROR = !Duplicate column names in table projection list
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-21556/.s.monetdb.36393
+QUERY = select *,* from (select 1 as c0, 2 as c0) as sub;
+ERROR = !Duplicate column names in table projection list
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-21556/.s.monetdb.36393
+QUERY = select * from (select 1 as c0, max(k) as c0 from (select 2, 3) tst(k, 
name) group by name) as sub;
+ERROR = !Duplicate column names in table projection list
+CODE  = 42000
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to