The Samba-Bugzilla – Attachment 11415 Details for
Bug 11477
getaddrinfo ignores AI_NUMERICHOST and unilaterally calls libc_getaddrinfo
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Proposed patch v2
0001-nwrap-Add-AI_NUMERICHOST-flag-support-for-getaddrinf.patch (text/plain), 3.34 KB, created by
Robin Hack
on 2015-09-07 08:51:13 UTC
(
hide
)
Description:
Proposed patch v2
Filename:
MIME Type:
Creator:
Robin Hack
Created:
2015-09-07 08:51:13 UTC
Size:
3.34 KB
patch
obsolete
>From f56055a1418a767f8afd71fb6dd98e86c2c65dc5 Mon Sep 17 00:00:00 2001 >From: Robin Hack <hack.robin@gmail.com> >Date: Mon, 7 Sep 2015 08:06:52 +0200 >Subject: [PATCH] nwrap: Add AI_NUMERICHOST flag support for getaddrinfo > function. > >Solves bug 11477. > >Signed-off-by: Robin Hack <hack.robin@gmail.com> >--- > src/nss_wrapper.c | 6 +++++ > tests/test_getaddrinfo.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 71 insertions(+) > >diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c >index 28c23d8..d3395d7 100644 >--- a/src/nss_wrapper.c >+++ b/src/nss_wrapper.c >@@ -3895,6 +3895,12 @@ static int nwrap_getaddrinfo(const char *node, > return ret; > } > >+ if ((hints != NULL) && (ret == EAI_NONAME) >+ && (hints->ai_flags & AI_NUMERICHOST)) >+ { >+ return ret; >+ } >+ > if (hints == NULL) { > hints = &default_hints; > } >diff --git a/tests/test_getaddrinfo.c b/tests/test_getaddrinfo.c >index 492913b..b7532ef 100644 >--- a/tests/test_getaddrinfo.c >+++ b/tests/test_getaddrinfo.c >@@ -371,6 +371,70 @@ static void test_nwrap_getaddrinfo_ipv6(void **state) > freeaddrinfo(res); > } > >+/* This test can be tricky. It can pass against raw glibc. >+ * Check if nss_wrapper is enabled is nice to have. >+ */ >+static void test_nwrap_getaddrinfo_flags_ai_numerichost(void **state) >+{ >+ struct addrinfo hints; >+ struct addrinfo *res; >+ int rc; >+ >+ (void) state; /* unused */ >+ >+ /* IPv4 */ >+ memset(&hints, 0, sizeof(struct addrinfo)); >+ hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ >+ hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */ >+ hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; /* For wildcard IP address */ >+ hints.ai_protocol = 0; /* Any protocol */ >+ hints.ai_canonname = NULL; >+ >+ rc = getaddrinfo("127.0.0.11", NULL, &hints, &res); >+ assert_int_equal(rc, 0); >+ >+ rc = getaddrinfo(NULL, "echo", &hints, &res); >+ assert_int_equal(rc, 0); >+ >+ /* Must fail because string instead of ip addr given */ >+ rc = getaddrinfo("magrathea.galaxy.site", NULL, &hints, &res); >+ assert_int_equal(rc, EAI_NONAME); >+ >+ rc = getaddrinfo("", NULL, &hints, &res); >+ assert_int_equal(rc, EAI_NONAME); >+ >+ rc = getaddrinfo("fail.me", "echo", &hints, &res); >+ assert_int_equal(rc, EAI_NONAME); >+ >+ hints.ai_family = AF_INET6; >+ rc = getaddrinfo("::1", NULL, &hints, &res); >+ assert_int_equal(rc, 0); >+ >+ rc = getaddrinfo("hello.world.example.dot.net", NULL, &hints, &res); >+ assert_int_equal(rc, EAI_NONAME); >+ >+ >+ /* Actually this just check if nss_wrapper is enabled. */ >+ hints.ai_family = AF_INET; >+ rc = getaddrinfo("127.0.0.11", NULL, &hints, &res); >+ assert_int_equal(rc, 0); >+ assert_non_null(res->ai_canonname); >+ assert_string_equal(res->ai_canonname, "magrathea.galaxy.site"); >+ >+ /* Should be directly handled by glibc */ >+ hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; /* For wildcard IP address */ >+ hints.ai_family = AF_INET6; >+ rc = getaddrinfo(NULL, "echo", &hints, &res); >+ assert_int_equal(rc, 0); >+ >+ /* DANGEROUS! BEWARE! FIRE! hints changed here! */ >+ hints.ai_flags = 0; >+ rc = getaddrinfo(NULL, "echo", &hints, &res); >+ assert_int_equal(rc, 0); >+ >+ freeaddrinfo(res); >+} >+ > int main(void) { > int rc; > >@@ -383,6 +447,7 @@ int main(void) { > unit_test(test_nwrap_getaddrinfo_null), > unit_test(test_nwrap_getaddrinfo_dot), > unit_test(test_nwrap_getaddrinfo_ipv6), >+ unit_test(test_nwrap_getaddrinfo_flags_ai_numerichost), > }; > > rc = run_tests(tests); >-- >1.9.3 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 11477
:
11414
| 11415