From 0024b8460dfe5e133f9e0d63ed4f75314dea2f82 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 19 Feb 2023 00:05:24 -0600 Subject: [PATCH] lseek: avoid SEEK_HOLE bugs in FreeBSD, macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This attempts to fix , a bug in GNU cp caused by a serious data corruption bug in FreeBSD and macOS. * doc/posix-functions/lseek.texi: Mention the bug. * lib/unistd.in.h (SEEK_DATA, SEEK_HOLE): Undef in macOS < 13 and FreeBSD < 14. FreeBSD fixed the bug sometime during FreeBSD 13 , so the "FreeBSD < 14" is conservative. It’s unknown when (or indeed whether) Apple fixed macOS but this patch guesses macOS 13. --- ChangeLog | 12 ++++++++++++ doc/posix-functions/lseek.texi | 5 +++++ lib/unistd.in.h | 12 ++++++++++++ 3 files changed, 29 insertions(+) diff --git a/ChangeLog b/ChangeLog index c1ca610548..c8e9726916 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2023-02-18 Paul Eggert + + lseek: avoid SEEK_HOLE bugs in FreeBSD, macOS + This attempts to fix , a bug in GNU cp + caused by a serious data corruption bug in FreeBSD and macOS. + * doc/posix-functions/lseek.texi: Mention the bug. + * lib/unistd.in.h (SEEK_DATA, SEEK_HOLE): Undef in macOS < 13 and + FreeBSD < 14. FreeBSD fixed the bug sometime during FreeBSD 13 + , so the "FreeBSD < 14" is + conservative. It’s unknown when (or indeed whether) Apple fixed + macOS but this patch guesses macOS 13. + 2023-02-18 Bruno Haible configmake: Add support for $build_os != $host_os. diff --git a/doc/posix-functions/lseek.texi b/doc/posix-functions/lseek.texi index 2f8e2b5877..3470524b12 100644 --- a/doc/posix-functions/lseek.texi +++ b/doc/posix-functions/lseek.texi @@ -37,4 +37,9 @@ IRIX 6.5. @item Some systems do not support @code{SEEK_DATA} and @code{SEEK_HOLE}: AIX, HP-UX, Microsoft Windows, NetBSD, OpenBSD. +@item +Some systems have a buggy @code{SEEK_DATA} and @code{SEEK_HOLE}, +and Gnulib works around the problem via @code{#undef SEEK_DATA} +and @code{#undef SEEK_HOLE}: +FreeBSD 13, macOS 12. @end itemize diff --git a/lib/unistd.in.h b/lib/unistd.in.h index bfc501e5a7..47b32eb445 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -40,6 +40,18 @@ # undef _GL_INCLUDING_UNISTD_H #endif +/* Avoid lseek bugs in FreeBSD, macOS . */ +#if defined __FreeBSD__ && __FreeBSD__ < 14 +# undef SEEK_DATA +# undef SEEK_HOLE +#elif (defined __APPLE__ && defined __MACH__ \ + && (!defined MAC_OS_X_VERSION_MIN_REQUIRED \ + || MAC_OS_X_VERSION_MIN_REQUIRED < 130000)) +# include /* It also defines the two macros. */ +# undef SEEK_DATA +# undef SEEK_HOLE +#endif + /* Get all possible declarations of gethostname(). */ #if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \ && !defined _GL_INCLUDING_WINSOCK2_H -- 2.39.2