From 0fd9856a4674efd8e88aecc3647b5f87b9e970cb Mon Sep 17 00:00:00 2001 From: des Date: Sun, 15 Aug 2004 22:22:35 +0000 Subject: 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 --- usr.bin/fetch/fetch.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'usr.bin/fetch') 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) -- cgit v1.1