]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cp: defend better against FreeBSD 9.1 zfs bug
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 30 Oct 2021 01:01:34 +0000 (18:01 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 30 Oct 2021 01:23:54 +0000 (18:23 -0700)
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.

src/copy.c

index cb9018f93d36d351f76f49b502a5185c613c4747..1cbc9480c903f59234d38700d2089073a6be4d60 100644 (file)
@@ -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;