summaryrefslogtreecommitdiffstats
path: root/usr.bin/fetch
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2004-08-15 22:22:35 +0000
committerdes <des@FreeBSD.org>2004-08-15 22:22:35 +0000
commit0fd9856a4674efd8e88aecc3647b5f87b9e970cb (patch)
tree90ffdc6aae07c5a6fa4b25b72e606fc14bb90117 /usr.bin/fetch
parent51081642b64d6cad3a79c9202d2f90c6c5d236a0 (diff)
downloadFreeBSD-src-0fd9856a4674efd8e88aecc3647b5f87b9e970cb.zip
FreeBSD-src-0fd9856a4674efd8e88aecc3647b5f87b9e970cb.tar.gz
Fix a couple of edge cases in which sb.st_size may be incorrect or
meaningless. In particular, don't assume that it is left untouched if stat(2) fails; that assumption happens to fail at high optimization levels on some platforms. MFC after: 1 week
Diffstat (limited to 'usr.bin/fetch')
-rw-r--r--usr.bin/fetch/fetch.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c
index d695234..ef82f4e 100644
--- a/usr.bin/fetch/fetch.c
+++ b/usr.bin/fetch/fetch.c
@@ -416,12 +416,23 @@ fetch(char *URL, const char *path)
* the connection later if we change our minds.
*/
sb.st_size = -1;
- if (!o_stdout && stat(path, &sb) == -1 && errno != ENOENT) {
- warnx("%s: stat()", path);
- goto failure;
+ if (!o_stdout) {
+ r = stat(path, &sb);
+ if (r == 0 && S_ISREG(sb.st_mode)) {
+ url->offset = sb.st_size;
+ } else {
+ /*
+ * Whatever value sb.st_size has now is either
+ * wrong (if stat(2) failed) or irrelevant (if the
+ * path does not refer to a regular file)
+ */
+ sb.st_size = -1;
+ if (r == -1 && errno != ENOENT) {
+ warnx("%s: stat()", path);
+ goto failure;
+ }
+ }
}
- if (!o_stdout && r_flag && S_ISREG(sb.st_mode))
- url->offset = sb.st_size;
/* start the transfer */
if (timeout)
OpenPOWER on IntegriCloud