Changeset: 69cbffd15412 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/69cbffd15412
Added Files:
        sql/test/BugTracker-2023/Tests/newurl-issue-7417.test
Modified Files:
        monetdb5/modules/atoms/str.c
        monetdb5/modules/atoms/url.c
        sql/test/BugTracker-2023/Tests/All
Branch: Dec2023
Log Message:

Fix crash when calling newurl(scheme, authority, path) with one or more NULL 
args. Added test for GH#7417.


diffs (78 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
@@ -4245,6 +4245,7 @@ trimchars(str *buf, size_t *buflen, size
        size_t len = 0, nlen = len_s * sizeof(int);
        int c, *cbuf;
 
+       assert(s);
        CHECK_STR_BUFFER_LENGTH(buf, buflen, nlen, malfunc);
        cbuf = *(int **) buf;
 
diff --git a/monetdb5/modules/atoms/url.c b/monetdb5/modules/atoms/url.c
--- a/monetdb5/modules/atoms/url.c
+++ b/monetdb5/modules/atoms/url.c
@@ -782,13 +782,24 @@ URLnew(url *u, str *val)
 static str
 URLnew3(url *u, str *protocol, str *server, str *file)
 {
+       str Protocol = *protocol;
+       str Server = *server;
+       str File = *file;
        size_t l;
 
-       l = strLen(*file) + strLen(*server) + strLen(*protocol) + 10;
+       if (strNil(File))
+               File = "";
+       else if (*File == '/')
+               File++;
+       if (strNil(Server))
+               Server = "";
+       if (strNil(Protocol))
+               Protocol = "";
+       l = strlen(File) + strlen(Server) + strlen(Protocol) + 10;
        *u = GDKmalloc(l);
        if (*u == NULL)
                throw(MAL, "url.newurl", SQLSTATE(HY013) MAL_MALLOC_FAIL);
-       snprintf(*u, l, "%s://%s/%s", *protocol, *server, *file);
+       snprintf(*u, l, "%s://%s/%s", Protocol, Server, File);
        return MAL_SUCCEED;
 }
 
diff --git a/sql/test/BugTracker-2023/Tests/All 
b/sql/test/BugTracker-2023/Tests/All
--- a/sql/test/BugTracker-2023/Tests/All
+++ b/sql/test/BugTracker-2023/Tests/All
@@ -20,3 +20,4 @@ between-crash-7413
 corr-issue-7414
 insert-delete-insert-crash-7415
 orderby-debug-crash-7416
+newurl-issue-7417
diff --git a/sql/test/BugTracker-2023/Tests/newurl-issue-7417.test 
b/sql/test/BugTracker-2023/Tests/newurl-issue-7417.test
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2023/Tests/newurl-issue-7417.test
@@ -0,0 +1,24 @@
+query T
+SELECT newurl(1,1,NULL)
+----
+1://1/
+
+query T
+SELECT TRIM(NULL, NULL)
+----
+NULL
+
+query T
+SELECT TRIM(newurl(1,1,NULL), null)
+----
+NULL
+
+query T
+SELECT TRIM(null, newurl(1,1,NULL))
+----
+NULL
+
+query T
+SELECT TRIM(newurl(1,1,NULL), newurl(1,1,NULL))
+----
+(empty)
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to