Code in mysql_connection.cpp tries to be smart and change the hostname
'localhost' to '127.0.0.1', but if the hostname is merely prefixed
with 'localhost' (for example "localhost_fwd"), it also changes it.
There may be legitimate instances where a user may not want all hosts
that *start* with 'localhost' to be changed, for example when
forwarding to another host/ip address.
I think it is dubious in general to change connection parameters
behind the covers for the "convenience" of the user. If the user
wants 127.0.0.1, then let them specify that. If they want
'localhost', then let them enter that and leave it alone.
In any case, changing things that are not strictly 'localhost' seems
especially bad. Here is an example of the logic, extracted from
mysql_connection.cpp:
% cat mysql_connector_bug.cc
#include <iostream>
#include <string>
using namespace std;
void cmp_host(const string& host) {
if (!host.compare(0, sizeof("localhost") - 1, "localhost")) {
cout << "Found localhost: " << host << endl;
}
}
int main() {
cmp_host("localhost");
cmp_host("localhost_forward");
}
% g++ mysql_connector_bug.cc
./a.out
Found localhost: localhost
Found localhost: localhost_forward
Bill
| Thread |
|---|
| • Overzealous change of hostnames to '127.0.0.1' | Bill Lear | 14 Dec |