summaryrefslogtreecommitdiff
path: root/ndb/tools
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 /ndb/tools
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)
Diffstat (limited to 'ndb/tools')
-rw-r--r--ndb/tools/ndb_config.cpp23
1 files changed, 19 insertions, 4 deletions
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;