summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <hartmut@mysql.com/linux.site>2006-09-13 23:19:18 +0200
committerunknown <hartmut@mysql.com/linux.site>2006-09-13 23:19:18 +0200
commitef5b4efd2289446fd0d55326d99b99a09513e023 (patch)
tree09e3f898957f10d5098d278d57a4972709b24437
parenta74f300ff27d5e76c075bfb542705f3ec19647c7 (diff)
downloadmariadb-git-ef5b4efd2289446fd0d55326d99b99a09513e023.tar.gz
Fixed host name comparison (still Bug #17582)
mysql-test/r/ndb_config.result: test case for Bug #17582 mysql-test/t/ndb_config.test: test case for Bug #17582 ndb/tools/ndb_config.cpp: gethostname() returns a pointer to a static buffer so we need to create a copy of the results before calling it on the 2nd host name, else we're effectively comparing a hostname to itself which is of course always true (Bug #17582)
-rw-r--r--mysql-test/r/ndb_config.result3
-rw-r--r--mysql-test/t/ndb_config.test5
-rw-r--r--ndb/tools/ndb_config.cpp23
3 files changed, 27 insertions, 4 deletions
diff --git a/mysql-test/r/ndb_config.result b/mysql-test/r/ndb_config.result
index ef5c924a398..9470cd7256c 100644
--- a/mysql-test/r/ndb_config.result
+++ b/mysql-test/r/ndb_config.result
@@ -9,3 +9,6 @@ ndbd,1,localhost ndbd,2,localhost ndbd,3,localhost ndbd,4,localhost ndb_mgmd,5,l
ndbd,2,localhost ndbd,3,localhost ndbd,4,localhost ndbd,5,localhost ndb_mgmd,6,localhost mysqld,1, mysqld,7, mysqld,8, mysqld,9, mysqld,10,
ndbd,3,localhost ndbd,4,localhost ndbd,5,localhost ndbd,6,localhost ndb_mgmd,1,localhost ndb_mgmd,2,localhost mysqld,11, mysqld,12, mysqld,13, mysqld,14, mysqld,15,
shm,3,4,35,3 shm,3,5,35,3 shm,3,6,35,3 shm,4,5,35,4 shm,4,6,35,4 shm,5,6,35,5 tcp,11,3,55,3 tcp,11,4,55,4 tcp,11,5,55,5 tcp,11,6,55,6 tcp,12,3,55,3 tcp,12,4,55,4 tcp,12,5,55,5 tcp,12,6,55,6 tcp,13,3,55,3 tcp,13,4,55,4 tcp,13,5,55,5 tcp,13,6,55,6 tcp,14,3,55,3 tcp,14,4,55,4 tcp,14,5,55,5 tcp,14,6,55,6 tcp,15,3,55,3 tcp,15,4,55,4 tcp,15,5,55,5 tcp,15,6,55,6 tcp,1,3,55,1 tcp,1,4,55,1 tcp,1,5,55,1 tcp,1,6,55,1 tcp,2,3,55,2 tcp,2,4,55,2 tcp,2,5,55,2 tcp,2,6,55,2
+1 2 3
+
+1 2 3
diff --git a/mysql-test/t/ndb_config.test b/mysql-test/t/ndb_config.test
index 4787abe86e2..f63c0087c1e 100644
--- a/mysql-test/t/ndb_config.test
+++ b/mysql-test/t/ndb_config.test
@@ -16,3 +16,8 @@
--exec $NDB_TOOLS_DIR/ndb_config --defaults-group-suffix=.cluster1 --defaults-file=$MYSQL_TEST_DIR/std_data/ndb_config_mycnf2.cnf --query=type,nodeid,host --mycnf 2> /dev/null
--exec $NDB_TOOLS_DIR/ndb_config --defaults-group-suffix=.cluster2 --defaults-file=$MYSQL_TEST_DIR/std_data/ndb_config_mycnf2.cnf --query=type,nodeid,host --mycnf 2> /dev/null
--exec $NDB_TOOLS_DIR/ndb_config --defaults-group-suffix=.cluster2 --defaults-file=$MYSQL_TEST_DIR/std_data/ndb_config_mycnf2.cnf --ndb-shm --connections --query=type,nodeid1,nodeid2,group,nodeidserver --mycnf 2> /dev/null
+
+
+--exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=nodeid --host=localhost --config-file=$NDB_BACKUP_DIR/config.ini 2> /dev/null
+--exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=nodeid --host=1.2.3.4 --config-file=$NDB_BACKUP_DIR/config.ini 2> /dev/null
+--exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=nodeid --host=127.0.0.1 --config-file=$NDB_BACKUP_DIR/config.ini 2> /dev/null
diff --git a/ndb/tools/ndb_config.cpp b/ndb/tools/ndb_config.cpp
index bf36a516f49..d89049cf1bd 100644
--- a/ndb/tools/ndb_config.cpp
+++ b/ndb/tools/ndb_config.cpp
@@ -411,28 +411,43 @@ HostMatch::eval(const Iter& iter)
if(iter.get(m_key, &valc) == 0)
{
- struct hostent *h1, *h2;
+ struct hostent *h1, *h2, copy1;
+ char *addr1;
+ int stat;
h1 = gethostbyname(m_value.c_str());
if (h1 == NULL) {
return 0;
}
+ // gethostbyname returns a pointer to a static structure
+ // so we need to copy the results before doing the next call
+ memcpy(&copy1, h1, sizeof(struct hostent));
+ addr1 = (char *)malloc(copy1.h_length);
+ memcpy(addr1, h1->h_addr, copy1.h_length);
+
h2 = gethostbyname(valc);
if (h2 == NULL) {
+ free(addr1);
return 0;
}
- if (h1->h_addrtype != h2->h_addrtype) {
+ if (copy1.h_addrtype != h2->h_addrtype) {
+ free(addr1);
return 0;
}
- if (h1->h_length != h2->h_length)
+ if (copy1.h_length != h2->h_length)
{
+ free(addr1);
return 0;
}
- return 0 == memcmp(h1->h_addr, h2->h_addr, h1->h_length);
+ stat = memcmp(addr1, h2->h_addr, copy1.h_length);
+
+ free(addr1);
+
+ return (stat == 0);
}
return 0;