From 33c9a74c88e9f17c4e3ab3767084fa4497734797 Mon Sep 17 00:00:00 2001 From: Jitka Plesnikova Date: Thu, 3 Apr 2025 08:32:37 +0200 Subject: [PATCH] Resolves: RHEL-85011 Backported fix of mysql_get_client_version() function for MariaDB Connector/C 3.1.10 and higher. It is in upstream since 1.22. Disable build for %{ix86}, beacuse mariadb is not built here. --- ...ix-mysql_get_client_version-function.patch | 83 +++++++++++++++++++ perl-DBD-MariaDB.spec | 16 +++- 2 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 DBD-MariaDB-1.21-Fix-mysql_get_client_version-function.patch diff --git a/DBD-MariaDB-1.21-Fix-mysql_get_client_version-function.patch b/DBD-MariaDB-1.21-Fix-mysql_get_client_version-function.patch new file mode 100644 index 0000000..a2622ab --- /dev/null +++ b/DBD-MariaDB-1.21-Fix-mysql_get_client_version-function.patch @@ -0,0 +1,83 @@ +From 9743bec52db5e8f1beb2b31e4a55d6ea1a4edcdd Mon Sep 17 00:00:00 2001 +From: Pali +Date: Fri, 8 Apr 2022 21:36:47 +0200 +Subject: [PATCH] Fix mysql_get_client_version() function + +MariaDB Connector/C 3.1.10 changed API of mysql_get_client_version() +function. Before that release it returned client version. With that release +it started returning Connector/C package version. + +So when compiling with MariaDB Connector/C client library, redefine +mysql_get_client_version() to always returns client version via function +mariadb_get_infov(MARIADB_CLIENT_VERSION_ID) call. + +Driver code expects for a long time that mysql_get_client_version() call +returns client version and not something different. + +Function mariadb_get_infov() is supported since MariaDB Connector/C 3.0+. + +Fixes: https://github.com/perl5-dbi/DBD-mysql/issues/333 +--- + Makefile.PL | 8 +++++++- + dbdimp.h | 26 ++++++++++++++++++++++++++ + 2 files changed, 33 insertions(+), 1 deletion(-) + +diff --git a/Makefile.PL b/Makefile.PL +index b9b046c..f28a8df 100644 +--- a/Makefile.PL ++++ b/Makefile.PL +@@ -757,7 +757,13 @@ sub Configure { + # https://jira.mariadb.org/browse/MDEV-16478 + $function .= "\n#if defined(MARIADB_BASE_VERSION) || defined(MARIADB_PACKAGE_VERSION)\nif (mysql_get_client_version() >= 100301 && mysql_get_client_version() < 100308) return 1;\n#endif\n"; + } +- $function .= 'return (mysql_get_client_version() == MYSQL_VERSION_ID) ? 0 : 1;'; ++ # MariaDB Connector/C 3.1.10+ has broken mysql_get_client_version() function, so use mariadb_get_infov(MARIADB_CLIENT_VERSION_ID) instead ++ $function .= "size_t version;\n"; ++ $function .= "#if defined(MARIADB_PACKAGE_VERSION) && defined(MARIADB_PACKAGE_VERSION_ID) && MARIADB_PACKAGE_VERSION_ID >= 30000\n"; ++ $function .= "if (mariadb_get_infov((void *)0, MARIADB_CLIENT_VERSION_ID, &version) != 0)\n"; ++ $function .= "#endif\n"; ++ $function .= "version = mysql_get_client_version();\n"; ++ $function .= 'return (version == MYSQL_VERSION_ID) ? 0 : 1;'; + # libmysqld is built using g++ rather than gcc and sometimes + # we have to use libstdc++ to resolve linking problems + foreach my $add_ldflags (undef, '-lstdc++') { +diff --git a/dbdimp.h b/dbdimp.h +index 41cc72a..aee608f 100644 +--- a/dbdimp.h ++++ b/dbdimp.h +@@ -322,6 +322,32 @@ PERL_STATIC_INLINE UV SvUV_nomg(pTHX_ SV *sv) + #define my_bool bool + #endif + ++/* ++ * MariaDB Connector/C 3.1.10 changed API of mysql_get_client_version() ++ * function. Before that release it returned client version. With that release ++ * it started returning Connector/C package version. ++ * ++ * So when compiling with MariaDB Connector/C client library, redefine ++ * mysql_get_client_version() to always returns client version via function ++ * mariadb_get_infov(MARIADB_CLIENT_VERSION_ID) call. ++ * ++ * Driver code expects for a long time that mysql_get_client_version() call ++ * returns client version and not something different. ++ * ++ * Function mariadb_get_infov() is supported since MariaDB Connector/C 3.0+. ++ */ ++#if defined(MARIADB_PACKAGE_VERSION) && defined(MARIADB_PACKAGE_VERSION_ID) && MARIADB_PACKAGE_VERSION_ID >= 30000 ++PERL_STATIC_INLINE unsigned long mariadb_get_client_version(void) ++{ ++ /* MARIADB_CLIENT_VERSION_ID really expects size_t type, documentation is wrong and says unsigned int. */ ++ size_t version; ++ if (mariadb_get_infov(NULL, MARIADB_CLIENT_VERSION_ID, &version) != 0) ++ version = mysql_get_client_version(); /* On error fallback to mysql_get_client_version() */ ++ return version; ++} ++#define mysql_get_client_version() mariadb_get_client_version() ++#endif ++ + /* MYSQL_SECURE_AUTH became a no-op from MySQL 5.7.5 and is removed from MySQL 8.0.3 */ + #if defined(MARIADB_BASE_VERSION) || MYSQL_VERSION_ID <= 50704 + #define HAVE_SECURE_AUTH +-- +2.49.0 + diff --git a/perl-DBD-MariaDB.spec b/perl-DBD-MariaDB.spec index dfd6bf7..d1c76e4 100644 --- a/perl-DBD-MariaDB.spec +++ b/perl-DBD-MariaDB.spec @@ -7,9 +7,12 @@ %bcond_without perl_DBD_MariaDB_enables_net_ssleay_test %endif +# mariadb is not built for %%{ix86} +ExcludeArch: %{ix86} + Name: perl-DBD-MariaDB Version: 1.21 -Release: 16%{?dist} +Release: 17%{?dist} Summary: MariaDB and MySQL driver for the Perl5 Database Interface (DBI) License: GPL+ or Artistic URL: https://metacpan.org/release/DBD-MariaDB/ @@ -21,6 +24,9 @@ Patch0: DBD-MariaDB-1.21-Run-test-setup-and-clean.patch # Fix test for changed value of mariadb_clientversion # mariadb-connector-c 3.2.x version number changed mariadb_clientversion to 3020x Patch1: DBD-MariaDB-fix-mariadb-connector-c-32x-test.patch +# Fix mysql_get_client_version() function for MariaDB Connector/C 3.1.10 +# and higher, in upstream since 1.22 +Patch2: DBD-MariaDB-1.21-Fix-mysql_get_client_version-function.patch BuildRequires: findutils BuildRequires: gcc BuildRequires: make @@ -108,8 +114,9 @@ with "%{_libexecdir}/%{name}/test". %prep %setup -q -n DBD-MariaDB-%{version} -%patch0 -p1 -%patch1 -p1 +%patch -P0 -p1 +%patch -P1 -p1 +%patch -P2 -p1 cp %{SOURCE1} %{SOURCE2} t/ # Help file to recognise the Perl scripts and normalize shebangs @@ -174,6 +181,9 @@ make test %{?with_perl_DBD_MariaDB_enables_leak_test:EXTENDED_TESTING=1} %{_libexecdir}/%{name} %changelog +* Wed Apr 02 2025 Jitka Plesnikova - 1.21-17 +- Resolves: RHEL-85011 + * Thu Feb 17 2022 Jitka Plesnikova - 1.21-16 - Fix test for mariadb-connector-c 3.2.x