summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/http.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2017-03-24 14:19:52 +0000
committerdes <des@FreeBSD.org>2017-03-24 14:19:52 +0000
commit9cc8c478616cc8ad4c03db6529c1064888fc1acf (patch)
tree988e2bfb49ffca19739e87e0d00446a65d7e1b95 /lib/libfetch/http.c
parent4df1b0ecbe8b97b7b2a33fe8acc3e1936f273f92 (diff)
downloadFreeBSD-src-9cc8c478616cc8ad4c03db6529c1064888fc1acf.zip
FreeBSD-src-9cc8c478616cc8ad4c03db6529c1064888fc1acf.tar.gz
MFH (r313974,r314596): open .netrc early in case we want to drop privs
MFH (r314396,r315143): fix a crash caused by an incorrect format string MFH (r314701): fix handling of 416 errors when requesting a range MFH (r315455): fix parsing of IP literals (square brackets) PR: 212065, 217723
Diffstat (limited to 'lib/libfetch/http.c')
-rw-r--r--lib/libfetch/http.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index bb509c1..fe4e9de 100644
--- a/lib/libfetch/http.c
+++ b/lib/libfetch/http.c
@@ -118,7 +118,7 @@ __FBSDID("$FreeBSD$");
|| (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,20 +1604,11 @@ http_request_body(struct url *URL, const char *op, struct url_stat *us,
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);
- 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);
+ snprintf(hbuf, sizeof(hbuf), "%s:%d", host, url->port);
+ host = hbuf;
}
/* send request */
@@ -1925,7 +1916,7 @@ http_request_body(struct url *URL, const char *op, struct url_stat *us,
/* requested range not satisfiable */
if (conn->err == HTTP_BAD_RANGE) {
- if (url->offset == size && url->length == 0) {
+ if (url->offset > 0 && url->length == 0) {
/* asked for 0 bytes; fake it */
offset = url->offset;
clength = -1;
OpenPOWER on IntegriCloud