Bug 1520257 - inet_pton fails to deal with IPv6 address with format like 0:0:1:0:0:0:ffff:0a001
Summary: inet_pton fails to deal with IPv6 address with format like 0:0:1:0:0:0:ffff:0...
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 27
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Carlos O'Donell
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-12-04 06:56 UTC by Jianwen Ji
Modified: 2017-12-04 13:02 UTC (History)
11 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-12-04 07:14:06 UTC
Type: Bug


Attachments (Terms of Use)

Description Jianwen Ji 2017-12-04 06:56:03 UTC
Description of problem:

When running IPv6 related tests on Fedora, inet_pton failed to deal with IPv6 address with format like 0:0:1:0:0:0:ffff:0a001


The source code:
$ cat test.c
#include <stdio.h>
#include <unistd.h>
#include <errno.h>

#include <netinet/in.h>
#include <arpa/inet.h>
struct {
        char    *addr;
        int     ismap;
} maptab[] = {
        {"2002::1", 0 },
        {"::ffff:10.0.0.1", 1 },
        {"::fffe:10.0.0.1", 0 },
        {"::7fff:10.0.0.1", 0 },
        {"0:0:0:0:0:0:ffff:0a001", 1 },
};

#define MAPSIZE (sizeof(maptab)/sizeof(maptab[0]))

int main(int argc, char **argv) 
{
	struct in6_addr in6;
	int i;

        for (i=0; i<MAPSIZE; ++i) {
                if (inet_pton(AF_INET6, maptab[i].addr, &in6) <= 0) {
                        fprintf(stderr, "\"%s\" is not a valid IPv6 address\n",
                                maptab[i].addr);
                        continue;
                }
        }
	return 0;
}



Version-Release number of selected component (if applicable):
4.14.2-300.fc27.x86_64

[root@lenovo-rd230-02 testcases]# rpm -qa | grep glibc
glibc-headers-2.26-16.fc27.x86_64
glibc-common-2.26-16.fc27.x86_64
glibc-langpack-en-2.26-16.fc27.x86_64
glibc-devel-2.26-16.fc27.x86_64
glibc-2.26-16.fc27.x86_64


How reproducible:
Always

Steps to Reproduce:
1. compile the reproducer
   # gcc -o test test.c
2. run the reproducer
   # ./test

Actual results:


Expected results:


Additional info:

It could pass on Fedora 25
$ uname -r
4.8.6-300.fc25.x86_64
$ rpm -qa | grep glibc
glibc-headers-2.24-3.fc25.x86_64
glibc-common-2.24-3.fc25.x86_64
glibc-all-langpacks-2.24-3.fc25.x86_64
glibc-2.24-3.fc25.x86_64
glibc-devel-2.24-3.fc25.x86_64

Comment 1 Florian Weimer 2017-12-04 07:14:06 UTC
This is not a bug.  RFC 4291 requires that the hexadecimal components contain one to four digits:

https://tools.ietf.org/html/rfc4291#section-2.2

Comment 2 Jianwen Ji 2017-12-04 07:53:38 UTC
(In reply to Florian Weimer from comment #1)
> This is not a bug.  RFC 4291 requires that the hexadecimal components
> contain one to four digits:
> 
> https://tools.ietf.org/html/rfc4291#section-2.2

Thanks for clarifying it!


Note You need to log in before you can comment on or make changes to this bug.