From 28a1e4b5994f842aa722f9c91969513d3e047e51 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Mon, 31 Mar 2025 11:02:35 +0200 Subject: [PATCH 1/6] Fix for CONC-762: Always set is_null and length in bind structure to avoid msan errors --- libmariadb/mariadb_stmt.c | 6 +++++ unittest/libmariadb/ps_bugs.c | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c index 07cf6b16..1c4914f7 100644 --- a/libmariadb/mariadb_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -414,6 +414,9 @@ int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row) stmt->bind[i].is_null= &stmt->bind[i].is_null_value; *stmt->bind[i].is_null= 1; stmt->bind[i].u.row_ptr= NULL; + if (!stmt->bind[i].length) + stmt->bind[i].length= &stmt->bind[i].length_value; + *stmt->bind[i].length= stmt->bind[i].length_value= 0; } } else { @@ -426,6 +429,9 @@ int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row) if (stmt->result_callback) stmt->result_callback(stmt->user_data, i, &row); else { + if (!stmt->bind[i].is_null) + stmt->bind[i].is_null= &stmt->bind[i].is_null_value; + *stmt->bind[i].is_null= 0; if (mysql_ps_fetch_functions[stmt->fields[i].type].pack_len >= 0) length= mysql_ps_fetch_functions[stmt->fields[i].type].pack_len; else diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index 0e3202d7..e6b46a89 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -5666,8 +5666,49 @@ static int test_conc176(MYSQL *mysql) return OK; } +static int test_conc762(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + MYSQL_BIND bind[2]; + my_bool is_null[2]= {1,1}; + unsigned long length[2]= {1,1}; + + rc= mysql_stmt_prepare(stmt, SL("SELECT NULL, 'foo'")); + check_stmt_rc(rc, stmt); + + memset(&bind, 0, sizeof(MYSQL_BIND) * 2); + + bind[0].buffer_type = MYSQL_TYPE_STRING; + bind[1].buffer_type = MYSQL_TYPE_STRING; + bind[0].is_null= &is_null[0]; + bind[1].is_null= &is_null[1]; + bind[0].buffer_length= bind[1].buffer_length= 0; + bind[0].length= &length[0]; + bind[1].length= &length[1]; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, bind); + + mysql_stmt_fetch(stmt); + FAIL_IF(is_null[0]==0, "Expected NULL value"); + FAIL_IF(is_null[1]==1, "Expected non NULL value"); + FAIL_IF(length[0]!=0, "Expected length=0"); + FAIL_IF(length[1]!=3, "Expected length=3"); + +// FAIL_IF(length[0] != 0, "Expected length=0"); + +//FAIL_IF(length[1] != 3, "Expected length=3)"; + + mysql_stmt_close(stmt); + return OK; +} + struct my_tests_st my_tests[] = { + {"test_conc762", test_conc762, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc176", test_conc176, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc739", test_conc739, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc633", test_conc633, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, From 8e371bbe8ea01a2a59be1764d89083a4c908d39e Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Tue, 1 Apr 2025 19:25:48 +0200 Subject: [PATCH 2/6] CONC-764: Build error in ma_context.c on android X18 is a platform-reserved register on Android, not a callee-save register. So it will not be touched by the spawned/resumed co-routine and must not be included in the GCC asm clobber list on this platform. Signed-off-by: Kristian Nielsen --- libmariadb/ma_context.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libmariadb/ma_context.c b/libmariadb/ma_context.c index 224783b2..120c1b9a 100644 --- a/libmariadb/ma_context.c +++ b/libmariadb/ma_context.c @@ -725,7 +725,11 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) [stack] "+r" (stack) : [save] "r" (save) : "x3", "x4", "x5", "x6", "x7", - "x9", "x10", "x11", "x14", "x15", "x18", "x30", + "x9", "x10", "x11", "x14", "x15", +#ifndef __ANDROID__ + "x18", +#endif + "x30", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", @@ -828,7 +832,11 @@ my_context_continue(struct my_context *c) : [ret] "=r" (ret) : [save] "r" (save) : "x1", "x2", "x3", "x4", "x5", "x6", "x7", - "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x18", "x30", + "x9", "x10", "x11", "x12", "x13", "x14", "x15", +#ifndef __ANDROID__ + "x18", +#endif + "x30", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", @@ -905,7 +913,11 @@ my_context_yield(struct my_context *c) : : [save] "r" (save) : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", - "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x18", "x30", + "x9", "x10", "x11", "x12", "x13", "x14", "x15", +#ifndef __ANDROID__ + "x18", +#endif + "x30", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", From 5b7df2276caeb0276ae8a7f70ff56a49983073cc Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Tue, 1 Apr 2025 20:32:49 +0200 Subject: [PATCH 3/6] CONC-764: Build error in ma_context.c on android Some research show that X18 is mentioned as a platform-reserved register on most non-linux platforms, including MacOS, Windows, and FreeBSD. So only put it in the clobber list in Linux. Note that the ma_context.c code does not itself use the X18 register in any way. On platforms where X18 is reserved, the co-routine code will preserve it. On platforms where co-routine code can modify X18, it does not need to be preserved. Putting X18 in the clobber list is only to avoid GCC itself generating code that requires that X18 is preserved. Signed-off-by: Kristian Nielsen --- libmariadb/ma_context.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libmariadb/ma_context.c b/libmariadb/ma_context.c index 120c1b9a..08a03cef 100644 --- a/libmariadb/ma_context.c +++ b/libmariadb/ma_context.c @@ -726,7 +726,7 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) : [save] "r" (save) : "x3", "x4", "x5", "x6", "x7", "x9", "x10", "x11", "x14", "x15", -#ifndef __ANDROID__ +#if defined(__linux__) && !defined(__ANDROID__) "x18", #endif "x30", @@ -833,7 +833,7 @@ my_context_continue(struct my_context *c) : [save] "r" (save) : "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x9", "x10", "x11", "x12", "x13", "x14", "x15", -#ifndef __ANDROID__ +#if defined(__linux__) && !defined(__ANDROID__) "x18", #endif "x30", @@ -914,7 +914,7 @@ my_context_yield(struct my_context *c) : [save] "r" (save) : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x9", "x10", "x11", "x12", "x13", "x14", "x15", -#ifndef __ANDROID__ +#if defined(__linux__) && !defined(__ANDROID__) "x18", #endif "x30", From ae748744513d8abd6a311ad171921de6c8f4a786 Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Wed, 9 Apr 2025 18:14:57 -0400 Subject: [PATCH 4/6] bump the VERSION --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c15e87d4..b817280f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ SET(CC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) SET(CPACK_PACKAGE_VERSION_MAJOR 3) SET(CPACK_PACKAGE_VERSION_MINOR 1) -SET(CPACK_PACKAGE_VERSION_PATCH 28) +SET(CPACK_PACKAGE_VERSION_PATCH 29) SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") MATH(EXPR MARIADB_PACKAGE_VERSION_ID "${CPACK_PACKAGE_VERSION_MAJOR} * 10000 + ${CPACK_PACKAGE_VERSION_MINOR} * 100 + From 7274f8f65640c456638a31070fc0df5403ef90c3 Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Wed, 9 Apr 2025 18:15:34 -0400 Subject: [PATCH 5/6] bump the VERSION --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbcd7bbe..48dc48ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ SET(CC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) SET(CPACK_PACKAGE_VERSION_MAJOR 3) SET(CPACK_PACKAGE_VERSION_MINOR 3) -SET(CPACK_PACKAGE_VERSION_PATCH 15) +SET(CPACK_PACKAGE_VERSION_PATCH 16) SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") MATH(EXPR MARIADB_PACKAGE_VERSION_ID "${CPACK_PACKAGE_VERSION_MAJOR} * 10000 + ${CPACK_PACKAGE_VERSION_MINOR} * 100 + From 52c1eb4d75bee19af046ec576bf02f3b5658ad33 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 3 Apr 2025 12:11:52 +1100 Subject: [PATCH 6/6] CONC-766 Disable clang -Wcast-function-type-strict for makecontext makecontext has a defined prototype in ucontext.h that differs from its expected usage. Disable the clang warning for this function call. --- libmariadb/ma_context.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libmariadb/ma_context.c b/libmariadb/ma_context.c index afc8acb8..bc385dcd 100644 --- a/libmariadb/ma_context.c +++ b/libmariadb/ma_context.c @@ -103,8 +103,21 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) c->user_data= d; c->active= 1; u.p= c; + /* + makecontext function expects function pointer to receive multiple + ints as an arguments, however is declared in ucontext.h header with + a void (empty) argument list. Ignore clang cast-function-type-strict + warning for this function call. + */ +# ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wcast-function-type-strict" +# endif makecontext(&c->spawned_context, (uc_func_t)my_context_spawn_internal, 2, u.a[0], u.a[1]); +# ifdef __clang__ +# pragma clang diagnostic pop +# endif return my_context_continue(c); }