From ad28b90c4dde83a0243af1fd78a2b8de4a183713 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 19 Aug 2021 19:18:24 -0600 Subject: [PATCH] We still need the pread/pwrite hack for HP-UX 11.11 at least. This time around, avoid defining _LARGEFILE64_SOURCE and just declare pread64/pwrite64 ourselves. --- config.h.in | 14 ++++++++++++++ configure | 38 ++++++++++++++++++++++++++++++++++++++ configure.ac | 11 ++++++++++- include/sudo_compat.h | 10 ++++++++-- 4 files changed, 70 insertions(+), 3 deletions(-) diff --git a/config.h.in b/config.h.in index 6ee7f616f..2b40b9c2e 100644 --- a/config.h.in +++ b/config.h.in @@ -153,6 +153,14 @@ don't. */ #undef HAVE_DECL_PATH_MAX +/* Define to 1 if you have the declaration of `pread64', and to 0 if you + don't. */ +#undef HAVE_DECL_PREAD64 + +/* Define to 1 if you have the declaration of `pwrite64', and to 0 if you + don't. */ +#undef HAVE_DECL_PWRITE64 + /* Define to 1 if you have the declaration of `QUAD_MAX', and to 0 if you don't. */ #undef HAVE_DECL_QUAD_MAX @@ -651,6 +659,9 @@ /* Define to 1 if you have the `pread' function. */ #undef HAVE_PREAD +/* Define to 1 if you have the `pread64' function. */ +#undef HAVE_PREAD64 + /* Define to 1 if you have the `priv_set' function. */ #undef HAVE_PRIV_SET @@ -678,6 +689,9 @@ /* Define to 1 if you have the `pwrite' function. */ #undef HAVE_PWRITE +/* Define to 1 if you have the `pwrite64' function. */ +#undef HAVE_PWRITE64 + /* Define to 1 if you have the `pw_dup' function. */ #undef HAVE_PW_DUP diff --git a/configure b/configure index ed053eb8e..af55375ee 100755 --- a/configure +++ b/configure @@ -20904,6 +20904,44 @@ if test "x$ac_cv_func_pread" = xyes then : printf "%s\n" "#define HAVE_PREAD 1" >>confdefs.h + # pread/pwrite on 32-bit HP-UX 11.x may not support large files + case "$host_os" in + hpux*|hiuxmpp*) + + for ac_func in pread64 pwrite64 +do : + as_ac_var=`printf "%s\n" "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes" +then : + cat >>confdefs.h <<_ACEOF +#define `printf "%s\n" "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + + ac_fn_check_decl "$LINENO" "pread64" "ac_cv_have_decl_pread64" "$ac_includes_default" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_pread64" = xyes +then : + ac_have_decl=1 +else $as_nop + ac_have_decl=0 +fi +printf "%s\n" "#define HAVE_DECL_PREAD64 $ac_have_decl" >>confdefs.h +ac_fn_check_decl "$LINENO" "pwrite64" "ac_cv_have_decl_pwrite64" "$ac_includes_default" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_pwrite64" = xyes +then : + ac_have_decl=1 +else $as_nop + ac_have_decl=0 +fi +printf "%s\n" "#define HAVE_DECL_PWRITE64 $ac_have_decl" >>confdefs.h + + +fi + +done + ;; + esac + else $as_nop case " $LIBOBJS " in diff --git a/configure.ac b/configure.ac index f5b037757..a416473e0 100644 --- a/configure.ac +++ b/configure.ac @@ -2542,7 +2542,16 @@ dnl Function checks dnl AC_FUNC_GETGROUPS AC_CHECK_FUNCS_ONCE([fexecve fmemopen killpg nl_langinfo faccessat wordexp getauxval fseeko]) -AC_CHECK_FUNCS([pread], [], [ +AC_CHECK_FUNCS([pread], [ + # pread/pwrite on 32-bit HP-UX 11.x may not support large files + case "$host_os" in + hpux*|hiuxmpp*) + AC_CHECK_FUNCS([pread64 pwrite64], [ + AC_CHECK_DECLS([pread64, pwrite64]) + ]) + ;; + esac +], [ AC_LIBOBJ(pread) SUDO_APPEND_COMPAT_EXP(sudo_pread) ]) diff --git a/include/sudo_compat.h b/include/sudo_compat.h index 750d97165..e45c9d274 100644 --- a/include/sudo_compat.h +++ b/include/sudo_compat.h @@ -347,17 +347,23 @@ int getdomainname(char *, size_t); #endif /* - * HP-UX 11.00 has broken pread/pwrite that can't handle a 64-bit off_t - * on 32-bit machines. + * HP-UX 11.00 has broken pread/pwrite on 32-bit machines when + * _FILE_OFFSET_BITS == 64. Use pread64/pwrite64 instead. */ #if defined(__hpux) && !defined(__LP64__) # ifdef HAVE_PREAD64 # undef pread # define pread(_a, _b, _c, _d) pread64((_a), (_b), (_c), (_d)) +# if defined(HAVE_DECL_PREAD64) && !HAVE_DECL_PREAD64 + ssize_t pread64(int fd, void *buf, size_t nbytes, off64_t offset); +# endif # endif # ifdef HAVE_PWRITE64 # undef pwrite # define pwrite(_a, _b, _c, _d) pwrite64((_a), (_b), (_c), (_d)) +# if defined(HAVE_DECL_PWRITE64) && !HAVE_DECL_PWRITE64 + ssize_t pwrite64(int fd, const void *buf, size_t nbytes, off64_t offset); +# endif # endif #endif /* __hpux && !__LP64__ */