Changeset: d40fc3fd0173 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d40fc3fd0173
Modified Files:
        sql/server/rel_unnest.c
        sql/test/SQLancer/Tests/sqlancer05.stable.out
Branch: Oct2020
Log Message:

Don't compare a random expression to a boolean without checking the type first


diffs (91 lines):

diff --git a/sql/server/rel_unnest.c b/sql/server/rel_unnest.c
--- a/sql/server/rel_unnest.c
+++ b/sql/server/rel_unnest.c
@@ -2747,7 +2747,7 @@ rewrite_ifthenelse(visitor *v, sql_rel *
 }
 
 static list *
-rewrite_compare_exps(visitor *v, list *exps)
+rewrite_compare_exps(visitor *v, sql_rel *rel, list *exps)
 {
        if (list_empty(exps))
                return exps;
@@ -2755,12 +2755,18 @@ rewrite_compare_exps(visitor *v, list *e
                sql_exp *e = n->data;
 
                if (!is_compare(e->type)) {
-                       n->data = e = exp_compare(v->sql->sa, e, 
exp_atom_bool(v->sql->sa, 1), cmp_equal);
+                       sql_subtype bt;
+                       sql_find_subtype(&bt, "boolean", 0, 0);
+                       if (!(e = exp_check_type(v->sql, &bt, rel, e, 
type_equal)))
+                               return NULL;
+                       n->data = exp_compare(v->sql->sa, e, 
exp_atom_bool(v->sql->sa, 1), cmp_equal);
                        v->changes++;
                }
                if (is_compare(e->type) && e->flag == cmp_or) {
-                       e->l = rewrite_compare_exps(v, e->l);
-                       e->r = rewrite_compare_exps(v, e->r);
+                       if (!(e->l = rewrite_compare_exps(v, rel, e->l)))
+                               return NULL;
+                       if (!(e->r = rewrite_compare_exps(v, rel, e->r)))
+                               return NULL;
                }
        }
        list_hash_clear(exps);
@@ -2772,7 +2778,8 @@ static sql_rel *
 rewrite_compare_exp(visitor *v, sql_rel *rel)
 {
        if ((is_select(rel->op) || is_join(rel->op) || is_semi(rel->op)) && 
!list_empty(rel->exps))
-               rel->exps = rewrite_compare_exps(v, rel->exps);
+               if (!(rel->exps = rewrite_compare_exps(v, rel, rel->exps)))
+                       return NULL;
        return rel;
 }
 
diff --git a/sql/test/SQLancer/Tests/sqlancer05.stable.out 
b/sql/test/SQLancer/Tests/sqlancer05.stable.out
--- a/sql/test/SQLancer/Tests/sqlancer05.stable.out
+++ b/sql/test/SQLancer/Tests/sqlancer05.stable.out
@@ -261,6 +261,43 @@ stdout of test 'sqlancer05` in directory
 % 1 # length
 [ 0    ]
 #ROLLBACK;
+#START TRANSACTION;
+#CREATE TABLE "sys"."t0" ("c0" DOUBLE, "c1" TIMESTAMP,
+#      CONSTRAINT "t0_c0_unique" UNIQUE ("c0"),
+#      CONSTRAINT "t0_c1_unique" UNIQUE ("c1"),
+#      CONSTRAINT "t0_c0_c1_unique" UNIQUE ("c0", "c1"),
+#      CONSTRAINT "t0_c0_fkey" FOREIGN KEY ("c0") REFERENCES "sys"."t0" ("c0")
+#);
+#COPY 4 RECORDS INTO "sys"."t0" FROM stdin USING DELIMITERS E'\t',E'\n','"';
+#NULL  "1970-01-19 09:37:48.000000"
+#NULL  "1970-01-25 15:39:05.000000"
+#NULL  "1970-01-25 02:16:22.000000"
+#NULL  "1970-01-20 18:57:37.000000"
+[ 4    ]
+#CREATE TABLE "sys"."t1" ("c0" DOUBLE,"c1" TIMESTAMP);
+#COPY 5 RECORDS INTO "sys"."t1" FROM stdin USING DELIMITERS E'\t',E'\n','"';
+#NULL  "1970-01-17 22:34:50.000000"
+#NULL  "1970-01-21 20:17:49.000000"
+#0.5197361696675626    NULL
+#0.46979060080234214   NULL
+#0.0047394257892724445 NULL
+[ 5    ]
+#SELECT t0.c1 FROM t0 WHERE (((((t0.c0) NOT IN (-1003666733, t0.c0))OR((t0.c0) 
NOT BETWEEN SYMMETRIC (((14)*(10))) AND (- (75)))))OR('TRUE'));
+% sys.t0 # table_name
+% c1 # name
+% timestamp # type
+% 26 # length
+[ 1970-01-19 09:37:48.000000   ]
+[ 1970-01-25 15:39:05.000000   ]
+[ 1970-01-25 02:16:22.000000   ]
+[ 1970-01-20 18:57:37.000000   ]
+#SELECT CAST(SUM(count) AS BIGINT) FROM (SELECT CAST((((((t0.c0) NOT IN (-10, 
t0.c0))OR((t0.c0) NOT  BETWEEN SYMMETRIC (((14)*(10))) AND (- 
(756050096)))))OR('TRUE')) AS INT) as count FROM t0) as res;
+% sys.%6 # table_name
+% %6 # name
+% bigint # type
+% 1 # length
+[ 4    ]
+#ROLLBACK;
 
 # 12:00:38 >  
 # 12:00:38 >  "Done."
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to