From: Paul Eggert Date: Sat, 30 Oct 2021 01:01:34 +0000 (-0700) Subject: cp: defend better against FreeBSD 9.1 zfs bug X-Git-Tag: v9.1~199 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9e31457bf6a63072b54a9324cdf59a09441a21f;p=thirdparty%2Fcoreutils.git cp: defend better against FreeBSD 9.1 zfs bug Problem reported by Pádraig Brady (Bug#51433#14). * src/copy.c (lseek_copy, infer_scantype): Report an error if lseek with SEEK_DATA or SEEK_HOLE returns less than -1, as this is an lseek bug. --- diff --git a/src/copy.c b/src/copy.c index cb9018f93d..1cbc9480c9 100644 --- a/src/copy.c +++ b/src/copy.c @@ -530,7 +530,7 @@ lseek_copy (int src_fd, int dest_fd, char *buf, size_t buf_size, off_t ext_end = lseek (src_fd, ext_start, SEEK_HOLE); if (ext_end < 0) { - if (errno != ENXIO) + if (! (ext_end == -1 && errno == ENXIO)) goto cannot_lseek; ext_end = src_total_size; if (ext_end <= ext_start) @@ -607,12 +607,8 @@ lseek_copy (int src_fd, int dest_fd, char *buf, size_t buf_size, } ext_start = lseek (src_fd, dest_pos, SEEK_DATA); - if (ext_start < 0) - { - if (errno != ENXIO) - goto cannot_lseek; - break; - } + if (ext_start < 0 && ! (ext_start == -1 && errno == ENXIO)) + goto cannot_lseek; } /* When the source file ends with a hole, we have to do a little more work, @@ -1097,10 +1093,11 @@ infer_scantype (int fd, struct stat const *sb, #ifdef SEEK_HOLE scan_inference->ext_start = lseek (fd, 0, SEEK_DATA); - if (0 <= scan_inference->ext_start) + if (0 <= scan_inference->ext_start + || (scan_inference->ext_start == -1 && errno == ENXIO)) return LSEEK_SCANTYPE; else if (errno != EINVAL && !is_ENOTSUP (errno)) - return errno == ENXIO ? LSEEK_SCANTYPE : ERROR_SCANTYPE; + return ERROR_SCANTYPE; #endif return ZERO_SCANTYPE;