perl5-dbi / DBD-MariaDB

Perl MariaDB driver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Test failures with MariaDB-10.6.4 + libmariadb3-3.2.3

Tux opened this issue · comments

As reported by the auto-build tools of openSUSE Tumbleweed, I cloned the git repo on Tumbleweed and was able to reproduce/confirm the failures

Linux 5.14.6-2-default [openSUSE Tumbleweed 20211001]  HP ZBook 15G3 Core(TM) i7-6820HQ CPU @ 2.70GHz/2700(8 cores) x86_64  32017 Mb

libmariadb3-3.2.3-78.14.x86_64
libmariadbd19-10.6.4-3.5.x86_64
libmariadbd-devel-10.6.4-3.5.x86_64
libmariadb-devel-3.2.3-78.14.x86_64
mariadb-10.6.4-3.5.x86_64
mariadb-bench-10.6.4-3.5.x86_64
mariadb-client-10.6.4-3.5.x86_64
mariadb-connector-odbc-3.1.10-32.27.x86_64
mariadb-errormessages-10.6.4-3.5.noarch
mariadb-tools-10.6.4-3.5.x86_64

t/10connect.t ........................... 1/? # mariadb_clientinfo is: 3.2.3
# mariadb_clientversion is: 30203
# mariadb_serverversion is: 100604
# mariadb_hostinfo is: Localhost via UNIX socket
# mariadb_serverinfo is: 10.6.4-MariaDB
# mariadb_stat is: Uptime: 464  Threads: 1  Questions: 13  Slow queries: 0  Opens: 17  Open tables: 10  Queries per second avg: 0.028
# mariadb_protoinfo is: 10
# SQL_DBMS_NAME is MariaDB
# SQL_DBMS_VER is 10.06.0400
# SQL_SERVER_NAME is Localhost via UNIX socket
# SQL_DRIVER_VER is 01.21.0000
# Default storage engine is: InnoDB
# @@character_set_client is: utf8mb4
# @@character_set_connection is: utf8mb4
# @@character_set_database is: utf8mb4
# @@character_set_results is: utf8mb4
# @@character_set_server is: utf8mb4
# @@collation_connection is: utf8mb4_unicode_ci
# @@collation_database is: utf8mb4_unicode_ci
# @@collation_server is: utf8mb4_unicode_ci
# auto_reconnects_failed is: 0
# auto_reconnects_ok is: 0

t/40server_prepare.t .................... 3/29
#   Failed test 'USE is not supported with mariadb_server_prepare_disable_fallback=1'
#   at t/40server_prepare.t line 80.
# Looks like you failed 1 test of 29.
t/40server_prepare.t .................... Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/29 subtests

t/45bind_no_backslash_escapes.t ......... 1/20
#   Failed test at t/45bind_no_backslash_escapes.t line 33.
#          got: ''string\string"string''string''
#     expected: 'X'737472696E675C737472696E6722737472696E6727737472696E67''
# Looks like you failed 1 test of 20.
t/45bind_no_backslash_escapes.t ......... Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/20 subtests

We're seeing this (at least the second one in t/45bind_no_backslash_escapes.t) in Debian as well:

https://bugs.debian.org/1002093
http://qa-logs.debian.net/2021/12/20/libdbd-mariadb-perl_1.21-4_unstable.log

commented

Hello @Tux and @gregoa, following patch should fix issue with escaping. Could you test it?

diff --git a/dbdimp.c b/dbdimp.c
index 73bd3f33f55d..433a1c071aa6 100644
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -627,6 +627,25 @@ static char **fill_out_embedded_options(char *options,
   return options_list;
 }
 
+#if MYSQL_VERSION_ID < 50001
+/* MySQL client prior to version 5.0.1 does not implement mysql_real_escape_string() for SERVER_STATUS_NO_BACKSLASH_ESCAPES */
+static unsigned long string_escape_quotes(char *to, const char *from, unsigned long len)
+{
+  const char *to_start = to;
+  const char *end = from + len;
+
+  while (from < end)
+  {
+    if (*from == '\'')
+      *to++ = '\'';
+    *to++ = *from++;
+  }
+
+  *to = '\0';
+  return to - to_start;
+}
+#endif
+
 /*
   constructs an SQL statement previously prepared with
   actual values replacing placeholders
@@ -838,9 +857,8 @@ static char *parse_params(
 #if MYSQL_VERSION_ID < 50001
             if (sock->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
             {
-              *ptr++ = 'X';
               *ptr++ = '\'';
-              ptr += mysql_hex_string(ptr, ph->value, ph->len);
+              ptr += string_escape_quotes(ptr, ph->value, ph->len);
               *ptr++ = '\'';
             }
             else
@@ -6411,9 +6429,8 @@ SV* mariadb_db_quote(SV *dbh, SV *str, SV *type)
 #if MYSQL_VERSION_ID < 50001
       if (imp_dbh->pmysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
       {
-        *sptr++ = 'X';
         *sptr++ = '\'';
-        sptr += mysql_hex_string(sptr, ptr, len);
+        sptr += string_escape_quotes(sptr, ptr, len);
         *sptr++ = '\'';
       }
       else
diff --git a/t/45bind_no_backslash_escapes.t b/t/45bind_no_backslash_escapes.t
index 13dce122ce90..eaf011b03401 100644
--- a/t/45bind_no_backslash_escapes.t
+++ b/t/45bind_no_backslash_escapes.t
@@ -18,10 +18,6 @@ if ($dbh->{mariadb_serverversion} < 50001) {
     plan skip_all => "Servers < 5.0.1 do not support sql_mode NO_BACKSLASH_ESCAPES";
 }
 
-if ($dbh->{mariadb_clientversion} < 50001) {
-    $id2_quoted_no_backslash = q(X'737472696E675C737472696E6722737472696E6727737472696E67');
-}
-
 plan tests => 20;
 
 ok $dbh->do('CREATE TEMPORARY TABLE t(id VARCHAR(255), value TEXT)');

Thanks for the patch, and nope, still fails:

#   Failed test 'USE is not supported with mariadb_server_prepare_disable_fallback=1'
#   at t/40server_prepare.t line 80.
# Looks like you failed 1 test of 29.
t/40server_prepare.t ....................
1..29
ok 1 - connecting
ok 2 - making slate clean
ok 3 - creating table
ok 4 - loading data
ok 5
ok 6
ok 7 - binding parameter
ok 8 - fetching data
ok 9 
ok 10 - cleaning up
ok 11 - making slate clean
ok 12 - creating test table
ok 13 
ok 14 - binding int
ok 15 - binding smallint
ok 16 - binding tinyint
ok 17 - binding bigint
ok 18 - inserting data
ok 19
ok 20 - cleaning up
ok 21 - making slate clean
ok 22 - creating test table
ok 23
ok 24 - insert t3
ok 25
not ok 26 - USE is not supported with mariadb_server_prepare_disable_fallback=1
ok 27 - USE is supported with mariadb_server_prepare_disable_fallback=0
ok 28
ok 29 - cleaning up
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/29 subtests
[…]
Test Summary Report
-------------------
t/40server_prepare.t                  (Wstat: 256 Tests: 29 Failed: 1)
  Failed test:  26
  Non-zero exit status: 1
Files=90, Tests=3516, 36 wallclock secs ( 0.63 usr  0.13 sys +  6.90 cusr  0.97 csys =  8.63 CPU)
Result: FAIL
Failed 1/90 test programs. 1/3516 subtests failed.

That's against mariadb 10.6.7, in case it matters.

At least now it's the "other" test which fails :)

commented

But above is a fix for issue with escaping (affects only test 45bind_no_backslash_escapes.t). Which seems to be fixed?

commented

Correct, I can't reproduce this failure anymore.

Perfect! So at least something as a first step :-)

But now I see the other one as well, which was not present back then.

Please report separate issue. Ideally one issue for one failure as different failures needs different investigation and different fix.

Alright, that's #167 now

commented

Pull request #168 was merged so I'm closing this issue (manually).