From 4bcef637f86773382d6d4fb15044fc14751124fa Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 13 Jan 2016 11:10:33 -0700 Subject: [PATCH] Work around the buggy pread(2) on 32-bit HP-UX 11.00 by using pread64() on that platform. --- config.h.in | 10 ++++++++++ configure | 25 +++++++++++++++++++++++++ configure.ac | 12 ++++++++++++ include/sudo_compat.h | 15 +++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/config.h.in b/config.h.in index 23ab0bff6..d1a1571b1 100644 --- a/config.h.in +++ b/config.h.in @@ -523,6 +523,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 @@ -541,6 +544,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 @@ -1089,6 +1095,10 @@ /* Number of bits in a file offset, on hosts where this is settable. */ #undef _FILE_OFFSET_BITS +/* Define to 1 to enable 64-bit versions of standard C functions on 32-bit + systems. */ +#undef _LARGEFILE64_SOURCE + /* Define for large files, on AIX-style hosts. */ #undef _LARGE_FILES diff --git a/configure b/configure index de475d93f..71efab53b 100755 --- a/configure +++ b/configure @@ -18081,6 +18081,31 @@ done +case "$host_os" in + hpux*) + if test X"$ac_cv_func_pread" = X"yes"; then + O_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS -D_LARGEFILE64_SOURCE" + for ac_func in pread64 pwrite64 +do : + as_ac_var=`$as_echo "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 `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + + +$as_echo "#define _LARGEFILE64_SOURCE 1" >>confdefs.h + + +fi +done + + CPPFLAGS="$O_CPPFLAGS" + fi + ;; +esac for ac_func in getgrouplist do : ac_fn_c_check_func "$LINENO" "getgrouplist" "ac_cv_func_getgrouplist" diff --git a/configure.ac b/configure.ac index 481433c68..f50deeeee 100644 --- a/configure.ac +++ b/configure.ac @@ -2385,6 +2385,18 @@ dnl Function checks dnl AC_FUNC_GETGROUPS AC_CHECK_FUNCS_ONCE([fexecve killpg nl_langinfo strftime pread pwrite openat]) +case "$host_os" in + hpux*) + if test X"$ac_cv_func_pread" = X"yes"; then + O_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS -D_LARGEFILE64_SOURCE" + AC_CHECK_FUNCS([pread64 pwrite64], [ + AC_DEFINE([_LARGEFILE64_SOURCE], [1], [Define to 1 to enable 64-bit versions of standard C functions on 32-bit systems.]) + ]) + CPPFLAGS="$O_CPPFLAGS" + fi + ;; +esac AC_CHECK_FUNCS([getgrouplist], [], [ case "$host_os" in aix*) diff --git a/include/sudo_compat.h b/include/sudo_compat.h index 8ca8d5ba0..8c6edf845 100644 --- a/include/sudo_compat.h +++ b/include/sudo_compat.h @@ -324,6 +324,21 @@ int _innetgr(const char *, const char *, const char *, const char *); 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. + */ +#if defined(__hpux) && !defined(__LP64__) +# ifdef HAVE_PREAD64 +# undef pread +# define pread(_a, _b, _c, _d) pread64((_a), (_b), (_c), (_d)) +# endif +# ifdef HAVE_PWRITE64 +# undef pwrite +# define pwrite(_a, _b, _c, _d) pwrite64((_a), (_b), (_c), (_d)) +# endif +#endif /* __hpux && !__LP64__ */ + /* We wrap OpenBSD's strtonum() to get translatable error strings. */ __dso_public long long sudo_strtonum(const char *, long long, long long, const char **); #undef strtonum -- 2.40.0