FreeBSD Bugzilla – Attachment 180744 Details for
Bug 217723
[patch] libfetch parses IPv6 addresses incorrectly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Rewrite host parser
libfetch-ipv6-literal.diff (text/plain), 3.94 KB, created by
Dag-Erling Smørgrav
on 2017-03-12 13:09:16 UTC
(
hide
)
Description:
Rewrite host parser
Filename:
MIME Type:
Creator:
Dag-Erling Smørgrav
Created:
2017-03-12 13:09:16 UTC
Size:
3.94 KB
patch
obsolete
>Index: lib/libfetch/common.c >=================================================================== >--- lib/libfetch/common.c (revision 314777) >+++ lib/libfetch/common.c (working copy) >@@ -248,37 +248,51 @@ > { > char hbuf[256], sbuf[8]; > struct addrinfo hints, *res; >- const char *sep, *host, *service; >+ const char *hb, *he, *sep; >+ const char *host, *service; > int err, len; > >- /* split address if necessary */ >- err = EAI_SYSTEM; >- if ((sep = strchr(addr, ':')) != NULL) { >+ /* first, check for a bracketed IPv6 address */ >+ if (*addr == '[') { >+ hb = addr + 1; >+ if ((sep = strchr(hb, ']')) == NULL) { >+ errno = EINVAL; >+ goto syserr; >+ } >+ he = sep++; >+ } else { >+ hb = addr; >+ sep = strchrnul(hb, ':'); >+ he = sep; >+ } >+ >+ /* see if we need to copy the host name */ >+ if (*he != '\0') { > len = snprintf(hbuf, sizeof(hbuf), >- "%.*s", (int)(sep - addr), addr); >+ "%.*s", (int)(he - hb), hb); > if (len < 0) >- return (NULL); >+ goto syserr; > if (len >= (int)sizeof(hbuf)) { > errno = ENAMETOOLONG; >- fetch_syserr(); >- return (NULL); >+ goto syserr; > } > host = hbuf; >- service = sep + 1; >- } else if (port != 0) { >+ } else { >+ host = hb; >+ } >+ >+ /* was it followed by a service name? */ >+ if (*sep == '\0' && port != 0) { > if (port < 1 || port > 65535) { > errno = EINVAL; >- fetch_syserr(); >- return (NULL); >+ goto syserr; > } >- if (snprintf(sbuf, sizeof(sbuf), "%d", port) < 0) { >- fetch_syserr(); >- return (NULL); >- } >- host = addr; >+ if (snprintf(sbuf, sizeof(sbuf), "%d", port) < 0) >+ goto syserr; > service = sbuf; >+ } else if (*sep != '\0') { >+ service = sep; > } else { >- host = addr; > service = NULL; > } > >@@ -292,6 +306,9 @@ > return (NULL); > } > return (res); >+syserr: >+ fetch_syserr(); >+ return (NULL); > } > > >Index: lib/libfetch/fetch.c >=================================================================== >--- lib/libfetch/fetch.c (revision 314777) >+++ lib/libfetch/fetch.c (working copy) >@@ -386,18 +386,17 @@ > } > > /* hostname */ >-#ifdef INET6 > if (*p == '[' && (q = strchr(p + 1, ']')) != NULL && > (*++q == '\0' || *q == '/' || *q == ':')) { >- if ((i = q - p - 2) > MAXHOSTNAMELEN) >+ if ((i = q - p) > MAXHOSTNAMELEN) > i = MAXHOSTNAMELEN; >- strncpy(u->host, ++p, i); >+ strncpy(u->host, p, i); > p = q; >- } else >-#endif >+ } else { > for (i = 0; *p && (*p != '/') && (*p != ':'); p++) > if (i < MAXHOSTNAMELEN) > u->host[i++] = *p; >+ } > > /* port */ > if (*p == ':') { >@@ -444,12 +443,12 @@ > } > > DEBUG(fprintf(stderr, >- "scheme: [%s]\n" >- "user: [%s]\n" >- "password: [%s]\n" >- "host: [%s]\n" >- "port: [%d]\n" >- "document: [%s]\n", >+ "scheme: \"%s\"\n" >+ "user: \"%s\"\n" >+ "password: \"%s\"\n" >+ "host: \"%s\"\n" >+ "port: \"%d\"\n" >+ "document: \"%s\"\n", > u->scheme, u->user, u->pwd, > u->host, u->port, u->doc)); > >Index: lib/libfetch/http.c >=================================================================== >--- lib/libfetch/http.c (revision 314777) >+++ lib/libfetch/http.c (working copy) >@@ -118,7 +118,7 @@ > || (xyz) == HTTP_USE_PROXY \ > || (xyz) == HTTP_SEE_OTHER) > >-#define HTTP_ERROR(xyz) ((xyz) > 400 && (xyz) < 599) >+#define HTTP_ERROR(xyz) ((xyz) >= 400 && (xyz) <= 599) > > > /***************************************************************************** >@@ -1604,21 +1604,12 @@ > if ((conn = http_connect(url, purl, flags)) == NULL) > goto ouch; > >+ /* append port number only if necessary */ > host = url->host; >-#ifdef INET6 >- if (strchr(url->host, ':')) { >- snprintf(hbuf, sizeof(hbuf), "[%s]", url->host); >+ if (url->port != fetch_default_port(url->scheme)) { >+ snprintf(hbuf, sizeof(hbuf), "%s:%d", host, url->port); > host = hbuf; > } >-#endif >- if (url->port != fetch_default_port(url->scheme)) { >- if (host != hbuf) { >- strcpy(hbuf, host); >- host = hbuf; >- } >- snprintf(hbuf + strlen(hbuf), >- sizeof(hbuf) - strlen(hbuf), ":%d", url->port); >- } > > /* send request */ > if (verbose)
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 Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 217723
: 180744