diff options
| author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-07-20 00:00:01 +0000 |
|---|---|---|
| committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-07-20 00:00:01 +0000 |
| commit | 5d74d3d4a6700f2e55d52b90b3b7b8703028532e (patch) | |
| tree | 1defff867a8492c2a31787445b00aa25a6689e77 | |
| parent | e70653fea897de99205fa5c0af58a392bbd5dd30 (diff) | |
Notes
| -rw-r--r-- | lib/libfetch/http.c | 18 | ||||
| -rw-r--r-- | usr.bin/fetch/fetch.c | 46 |
2 files changed, 36 insertions, 28 deletions
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c index ce748c5c646f..06dad22ade4a 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -825,7 +825,7 @@ _http_request(struct url *URL, char *op, struct url_stat *us, char *flags) /* other headers */ _http_cmd(fd, "Host: %s:%d", host, url->port); _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, __progname); - if (URL->offset) + if (url->offset) _http_cmd(fd, "Range: bytes=%lld-", url->offset); _http_cmd(fd, "Connection: close"); _http_cmd(fd, ""); @@ -950,19 +950,21 @@ _http_request(struct url *URL, char *op, struct url_stat *us, char *flags) goto ouch; } + /* too far? */ + if (offset > url->offset) { + _http_seterr(HTTP_PROTOCOL_ERROR); + goto ouch; + } + + /* report back real offset */ + URL->offset = offset; + /* wrap it up in a FILE */ if ((f = chunked ? _http_funopen(fd) : fdopen(fd, "r")) == NULL) { _fetch_syserr(); goto ouch; } - while (offset++ < url->offset) - if (fgetc(f) == EOF) { - _fetch_syserr(); - fclose(f); - f = NULL; - } - if (url != URL) fetchFreeURL(url); diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c index 17ed5d82529d..987bc06b845b 100644 --- a/usr.bin/fetch/fetch.c +++ b/usr.bin/fetch/fetch.c @@ -258,6 +258,8 @@ fetch(char *URL, char *path) */ if (r_flag && !o_stdout && stat(path, &sb) != -1) url->offset = sb.st_size; + else + sb.st_size = 0; /* start the transfer */ if ((f = fetchXGet(url, &us, flags)) == NULL) { @@ -292,7 +294,7 @@ fetch(char *URL, char *path) if (o_stdout) { /* output to stdout */ of = stdout; - } else if (url->offset) { + } else if (sb.st_size) { /* resume mode, local file exists */ if (!F_flag && us.mtime && sb.st_mtime != us.mtime) { /* no match! have to refetch */ @@ -306,25 +308,29 @@ fetch(char *URL, char *path) goto signal; } else { us.size += url->offset; - } - if (us.size == sb.st_size) - /* nothing to do */ - goto success; - if (sb.st_size > us.size) { - /* local file too long! */ - warnx("%s: local file (%lld bytes) is longer " - "than remote file (%lld bytes)", - path, sb.st_size, us.size); - goto failure; - } - /* we got through, open local file in append mode */ - /* - * XXX there's a race condition here - the file we open is not - * necessarily the same as the one we stat()'ed earlier... - */ - if ((of = fopen(path, "a")) == NULL) { - warn("%s: open()", path); - goto failure; + if (us.size == sb.st_size) + /* nothing to do */ + goto success; + if (sb.st_size > us.size) { + /* local file too long! */ + warnx("%s: local file (%lld bytes) is longer " + "than remote file (%lld bytes)", + path, sb.st_size, us.size); + goto failure; + } + /* we got through, open local file and seek to offset */ + /* + * XXX there's a race condition here - the file we open is not + * necessarily the same as the one we stat()'ed earlier... + */ + if ((of = fopen(path, "a")) == NULL) { + warn("%s: fopen()", path); + goto failure; + } + if (fseek(of, url->offset, SEEK_SET) == -1) { + warn("%s: fseek()", path); + goto failure; + } } } if (m_flag && stat(path, &sb) != -1) { |
