[Python-modules-team] Bug#921599: Bug#921599: python-mysqldb: always connects to localhost ignoring host entry in option file

Peter Pentchev roam at ringlet.net
Sun Feb 10 15:28:34 GMT 2019


Control: reassign -1 src:mariadb-10.3
Control: tag -1 + upstream patch

On Thu, Feb 07, 2019 at 03:31:26AM +0100, Alan Krempler wrote:
> Package: python-mysqldb
> Version: 1.3.10-2
> Severity: normal
> 
> When connecting like this:
> connection = MySQLdb.connect(read_default_file=dbconfig)
> lines in the option file specifying a remote host are ignored.
> Whatever host is specified in the option file, python-mysqldb always attempts a
> connection to localhost.
> 
> Named host parameters to MySQLdb.connect() are handled correctly.

Hi,

Thanks for reporting this! I seem to have chased it down to a problem in
MariaDB's default implementation of the mysql_real_connect() function;
it seems that it decides what host to connect to before it checks
whether a configuration file to read was specified.

To the MariaDB maintainers: I'm attaching a simple patch that fixes
the problem for me, as well as a program to test for it. To run the test
program, you'd need a MariaDB user account that is only allowed to
connect from a non-loopback address (I used the 192.168.x.x address on
one of my network cards) and a configuration file with a "client"
section specifying the username and password for the account and
a non-loopback "host" setting.  Without the attached patch, the program
will fail to connect if a hostname is not specified on the command line;
with the patch, a null hostname passed to mysql_real_connect() will
cause the function to read it correctly from the config file.

I believe that this patch, or some version of it, should be submitted
upstream; I could do that if the maintainers are too busy, but I don't
want to step on any toes or miss the chance to use an already
established relationship between the maintainers and the MariaDB
developers.  Also, of course, the maintainers should feel free to
reformat the patch in any way that fits their workflow if they decide to
include it in the Debian package.

Thanks for reading this far, and keep up the great work, everyone!

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} pp at storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13
-------------- next part --------------
Description: Allow the server host to be specified in the defaults file.
Bug-Debian: https://bugs.debian.org/921599
Forwarded: no
Author: Peter Pentchev <roam at ringlet.net>
Last-Update: 2019-02-10

--- a/libmariadb/libmariadb/mariadb_lib.c
+++ b/libmariadb/libmariadb/mariadb_lib.c
@@ -1205,11 +1205,6 @@
   if (!mysql->methods)
     mysql->methods= &MARIADB_DEFAULT_METHODS;
 
-  if (!host || !host[0])
-    host = mysql->options.host;
-
-  ma_set_connect_attrs(mysql, host);
-
   if (net->pvio)  /* check if we are already connected */
   {
     SET_CLIENT_ERROR(mysql, CR_ALREADY_CONNECTED, SQLSTATE_UNKNOWN, 0);
@@ -1228,6 +1223,11 @@
     mysql->options.my_cnf_file=mysql->options.my_cnf_group=0;
   }
 
+  if (!host || !host[0])
+    host = mysql->options.host;
+
+  ma_set_connect_attrs(mysql, host);
+
 #ifndef WIN32
   if (mysql->options.protocol > MYSQL_PROTOCOL_SOCKET)
   {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: myconn.c
Type: text/x-csrc
Size: 1017 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/python-modules-team/attachments/20190210/72e501c5/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/python-modules-team/attachments/20190210/72e501c5/attachment.sig>


More information about the Python-modules-team mailing list