Skip to content

Commit a35eb61

Browse files
committed
Bug29770682: IS FALSE is being interpreted as IS TRUE
Fix CAST(val as NOT_KNOWN_TYPE) segmentation fault
1 parent dd9c090 commit a35eb61

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

cdk/parser/expr_parser.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ std::string Expr_parser_base::parse_cast_type()
215215
parse_error("Expected cast type");
216216

217217
Keyword::Type type = Keyword::get(*token);
218+
219+
if (Keyword::NONE == type)
220+
parse_error("Unexpected cast type");
221+
218222
type_str = Keyword::name(type);
219223

220224
switch (type)
@@ -242,7 +246,7 @@ std::string Expr_parser_base::parse_cast_type()
242246
break;
243247

244248
default:
245-
parse_error("Expected cast type");
249+
parse_error("Unexpected cast type");
246250

247251
}
248252

@@ -1695,7 +1699,7 @@ Expression* Expr_parser_base::parse_ilri(Processor *prc)
16951699
switch (Keyword::get(*t))
16961700
{
16971701
case Keyword::L_TRUE: aprc->list_el()->scalar()->val()->yesno(true); break;
1698-
case Keyword::L_FALSE: aprc->list_el()->scalar()->val()->yesno(true); break;
1702+
case Keyword::L_FALSE: aprc->list_el()->scalar()->val()->yesno(false); break;
16991703
case Keyword::L_NULL: aprc->list_el()->scalar()->val()->null(); break;
17001704
default:
17011705
t = NULL; // this indicates error

devapi/tests/bugs-t.cc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,5 +641,22 @@ TEST_F(Bugs, bug29525077)
641641
}
642642
}
643643
sess.dropSchema("bug29525077_int_types");
644+
}
644645

645-
}
646+
TEST_F(Bugs, is_false)
647+
{
648+
SKIP_IF_NO_XPLUGIN
649+
auto schema = get_sess().createSchema("test", true);
650+
auto coll = schema.createCollection("is_false", true);
651+
coll.remove("true").execute();
652+
coll.add(DbDoc(R"({"val": 0 })")).execute();
653+
coll.add(DbDoc(R"({"val": 1 })")).execute();
654+
coll.add(DbDoc(R"({"val": 1 })")).execute();
655+
// Since boolean is not an expected type, it should throw error
656+
// Had a segmentation fault issue
657+
EXPECT_THROW(coll.find("cast(val as boolean) is false").execute(),
658+
mysqlx::Error);
659+
EXPECT_EQ(1, coll.find("val is false").execute().count());
660+
auto tbl = schema.getCollectionAsTable("is_false");
661+
EXPECT_EQ(1, tbl.select().where("doc->$.val is false").execute().count());
662+
}

0 commit comments

Comments
 (0)