port numbers should always be interpreted as decimal
authorRich Felker <dalias@aerifal.cx>
Mon, 1 Aug 2011 04:11:25 +0000 (00:11 -0400)
committerRich Felker <dalias@aerifal.cx>
Mon, 1 Aug 2011 04:11:25 +0000 (00:11 -0400)
per POSIX and RFC 3493:

If the specified address family is AF_INET, AF_INET6, or AF_UNSPEC,
the service can be specified as a string specifying a decimal port
number.

021 is a valid decimal number, therefore, interpreting it as octal
seems to be non-conformant.

src/network/getaddrinfo.c

index 494b412..e5fa519 100644 (file)
@@ -76,7 +76,7 @@ int getaddrinfo(const char *host, const char *serv, const struct addrinfo *hint,
 
        if (serv) {
                if (!*serv) return EAI_SERVICE;
 
        if (serv) {
                if (!*serv) return EAI_SERVICE;
-               port = strtoul(serv, &z, 0);
+               port = strtoul(serv, &z, 10);
                if (!*z && port > 65535) return EAI_SERVICE;
                if (!port) {
                        if (flags & AI_NUMERICSERV) return EAI_SERVICE;
                if (!*z && port > 65535) return EAI_SERVICE;
                if (!port) {
                        if (flags & AI_NUMERICSERV) return EAI_SERVICE;