libSystem: inet_pton() or inet_ntop() converts wrong ipv6 addressed like: ::12
libSystem: inet_pton() or inet_ntop() converts wrong ipv6 addressed like: ::12
- Subject: libSystem: inet_pton() or inet_ntop() converts wrong ipv6 addressed like: ::12
- From: Robin Hack <email@hidden>
- Date: Mon, 04 Jan 2016 15:30:13 +0100
Hi mighty brains!
I would like to report possible bug in libSystem.
While porting nss_wrapper (part of
cwrap.org) project one with my test fails when I tried to work with ipv6 in form: ::12.
After close debugging it looks like libSystem contain bug which is reproducible by attached reproducer.
Core problem:
Looks like one of inet_*() functions are not able to translate ipv6 addresses in form ::XX where XX are numbers.
Intresting fact is: ::1 works as expected.
Steps to Reproduce:
1) compile attached file libSystem-bug.c
2) run
Expected Results:
Output of attached reproduceer. Same results on (FreeBSD, OmniOS, Linux):
PASS: match with '::1' found!
result (pointer): ::12
result (buffer): ::12
PASS: match with '::12' found!
Actual Results:
PASS: match with '::1' found!
result (pointer): ::0.0.0.18
result (buffer): ::0.0.0.18
FAIL: no match with '::12' found!
Version:
10.9 and 10.11 (with latest updates).
Notes:
* I tested this behavior across different operating systems (FreeBSD, OmniOS - aka Solaris, Linux Fedora 20).
* I already opened bug 23739955 however I feel that this bug report would be better here.
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
char BUFF[256];
const char *res;
struct {
union {
struct in_addr v4;
struct in6_addr v6;
} in;
} addr;
/* Works fine */
memset(&addr.in.v6, '\0', sizeof(addr.in.v6));
inet_pton(AF_INET6, "::1", &addr.in.v6);
res = inet_ntop(AF_INET6, &addr.in.v6, BUFF, INET6_ADDRSTRLEN);
if (strcmp(res, "::1") == 0) {
printf("PASS: match with '::1' found!\n");
}
/* ====================================================== */
/* Most interesting part */
memset(&addr.in.v6, '\0', sizeof(addr.in.v6));
inet_pton(AF_INET6, "::12", &addr.in.v6);
res = inet_ntop(AF_INET6, &addr.in.v6, BUFF, INET6_ADDRSTRLEN);
/* ====================================================== */
printf("result (pointer): %s\n", res);
printf("result (buffer): %s\n", BUFF);
if (strcmp(res, "::12") == 0) {
printf("PASS: match with '::12' found!\n");
return EXIT_SUCCESS;
}
printf("FAIL: no match with '::12' found!\n");
return EXIT_FAILURE;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden