Changeset: ed92065ce4de for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ed92065ce4de
Modified Files:
        monetdb5/modules/atoms/str.c
        sql/test/SQLancer/Tests/SingleServer
        sql/test/SQLancer/Tests/sqlancer01.sql
        sql/test/SQLancer/Tests/sqlancer01.stable.out
Branch: Jun2020
Log Message:

Fixed trim functions bug by checking the length of the second argument


diffs (140 lines):

diff --git a/monetdb5/modules/atoms/str.c b/monetdb5/modules/atoms/str.c
--- a/monetdb5/modules/atoms/str.c
+++ b/monetdb5/modules/atoms/str.c
@@ -3745,10 +3745,10 @@ STRRtrim(str *res, const str *arg1)
 
 /* return a list of codepoints in s */
 static int *
-trimchars(const char *s, size_t *n)
+trimchars(const char *s, size_t *n, size_t len_s)
 {
        size_t len = 0;
-       int *chars = GDKmalloc(strlen(s) * sizeof(int));
+       int *chars = GDKmalloc(len_s * sizeof(int));
        int c;
 
        if (chars == NULL)
@@ -3772,15 +3772,15 @@ str
 STRStrip2(str *res, const str *arg1, const str *arg2)
 {
        const char *s = *arg1;
-       size_t len;
-       size_t n;
-       size_t nchars;
+       size_t len, n, nchars, n2;
        int *chars;
 
        if (strNil(s) || strNil(*arg2)) {
                *res = GDKstrdup(str_nil);
+       } else if ((n2 = strlen(*arg2)) == 0) {
+               *res = GDKstrdup(*arg1);
        } else {
-               chars = trimchars(*arg2, &nchars);
+               chars = trimchars(*arg2, &nchars, n2);
                if (chars == NULL)
                        throw(MAL, "str.trim", SQLSTATE(HY013) MAL_MALLOC_FAIL);
                len = strlen(s);
@@ -3802,15 +3802,15 @@ str
 STRLtrim2(str *res, const str *arg1, const str *arg2)
 {
        const char *s = *arg1;
-       size_t len;
-       size_t n;
-       size_t nchars;
+       size_t len, n, nchars, n2;
        int *chars;
 
        if (strNil(s) || strNil(*arg2)) {
                *res = GDKstrdup(str_nil);
+       } else if ((n2 = strlen(*arg2)) == 0) {
+               *res = GDKstrdup(*arg1);
        } else {
-               chars = trimchars(*arg2, &nchars);
+               chars = trimchars(*arg2, &nchars, n2);
                if (chars == NULL)
                        throw(MAL, "str.trim", SQLSTATE(HY013) MAL_MALLOC_FAIL);
                len = strlen(s);
@@ -3829,15 +3829,15 @@ str
 STRRtrim2(str *res, const str *arg1, const str *arg2)
 {
        const char *s = *arg1;
-       size_t len;
-       size_t n;
-       size_t nchars;
+       size_t len, n, nchars, n2;
        int *chars;
 
        if (strNil(s) || strNil(*arg2)) {
                *res = GDKstrdup(str_nil);
+       } else if ((n2 = strlen(*arg2)) == 0) {
+               *res = GDKstrdup(*arg1);
        } else {
-               chars = trimchars(*arg2, &nchars);
+               chars = trimchars(*arg2, &nchars, n2);
                if (chars == NULL)
                        throw(MAL, "str.trim", SQLSTATE(HY013) MAL_MALLOC_FAIL);
                len = strlen(s);
diff --git a/sql/test/SQLancer/Tests/SingleServer 
b/sql/test/SQLancer/Tests/SingleServer
--- a/sql/test/SQLancer/Tests/SingleServer
+++ b/sql/test/SQLancer/Tests/SingleServer
@@ -0,0 +1,1 @@
+--set raw_strings=true
diff --git a/sql/test/SQLancer/Tests/sqlancer01.sql 
b/sql/test/SQLancer/Tests/sqlancer01.sql
--- a/sql/test/SQLancer/Tests/sqlancer01.sql
+++ b/sql/test/SQLancer/Tests/sqlancer01.sql
@@ -25,7 +25,7 @@ insert into integers(i) values(((length(reverse('8 
\rcr੧[bp1eMY쫺4j5s뮯!<Rn4*}')))>>(((- (- (528640982)))&(ascii('528640982')))))); 
--Bug 6885
 SELECT i from integers order by i;
        -- NULL
        -- 0
-select reverse('8 \rcr੧[bp1eMY쫺4j5s뮯!<Rn4*}');
+select reverse(r'8 \rcr੧[bp1eMY쫺4j5s뮯!<Rn4*}');
 
 select true in (1 in (1));
        -- true
@@ -72,6 +72,13 @@ SELECT v3.c0 FROM v3, v0, tbl_productsal
        -- empty
 ROLLBACK;
 
+START TRANSACTION; --Bug 6894
+insert into tbl_productsales(product_name, totalsales) values (((cast(0.1 as 
string))||(charindex(cast(((((1)*(-1)))&(((-1)|(-1)))) as string), 
+((((rtrim('0.9407860360743894', ''))||(1)))||(cast(1.44041702E9 as 
string(75)))), 
+((- (((1)*(-1))))*(1))))), -1833694753);
+select rtrim('0.9407860360743894', '');
+ROLLBACK;
+
 DROP TABLE tbl_ProductSales;
 DROP TABLE another_T;
 DROP TABLE integers;
diff --git a/sql/test/SQLancer/Tests/sqlancer01.stable.out 
b/sql/test/SQLancer/Tests/sqlancer01.stable.out
--- a/sql/test/SQLancer/Tests/sqlancer01.stable.out
+++ b/sql/test/SQLancer/Tests/sqlancer01.stable.out
@@ -105,8 +105,8 @@ stdout of test 'sqlancer01` in directory
 % .%2 # table_name
 % %2 # name
 % clob # type
-% 28 # length
-[ "}*4nR<!뮯s5j4쫺YMe1pb[੧rc\r 8"        ]
+% 29 # length
+[ "}*4nR<!뮯s5j4쫺YMe1pb[੧rcr\\ 8"       ]
 #select true in (1 in (1));
 % .%6 # table_name
 % %6 # name
@@ -242,6 +242,18 @@ stdout of test 'sqlancer01` in directory
 % double # type
 % 24 # length
 #ROLLBACK;
+#START TRANSACTION; --Bug 6894
+#insert into tbl_productsales(product_name, totalsales) values (((cast(0.1 as 
string))||(charindex(cast(((((1)*(-1)))&(((-1)|(-1)))) as string), 
+#((((rtrim('0.9407860360743894', ''))||(1)))||(cast(1.44041702E9 as 
string(75)))), 
+#((- (((1)*(-1))))*(1))))), -1833694753);
+[ 1    ]
+#select rtrim('0.9407860360743894', '');
+% .%2 # table_name
+% %2 # name
+% varchar # type
+% 18 # length
+[ "0.9407860360743894" ]
+#ROLLBACK;
 #DROP TABLE tbl_ProductSales;
 #DROP TABLE another_T;
 #DROP TABLE integers;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to