From 819c5b01a90e738ced6af237a6ae0d1aff981127 Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Fri, 6 Dec 2024 09:58:58 -0600 Subject: [PATCH] Check for tcgetattr / tcsetattr before using it for readpassphrase implementation (#2424) This is mainly for non-cygwin newlib platforms that don't have tcgetattr / tcsetattr implemented --- CMakeLists.txt | 2 ++ build/cmake/config.h.in | 6 ++++++ configure.ac | 1 + contrib/android/config/android.h | 2 ++ contrib/android/config/linux_host.h | 2 ++ contrib/android/config/windows_host.h | 6 ++++++ libarchive/config_freebsd.h | 2 ++ libarchive_fe/passphrase.c | 10 ++++++++-- 8 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f38dd064..9fd47412f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1525,6 +1525,8 @@ CHECK_FUNCTION_EXISTS_GLIBC(strnlen HAVE_STRNLEN) CHECK_FUNCTION_EXISTS_GLIBC(strrchr HAVE_STRRCHR) CHECK_FUNCTION_EXISTS_GLIBC(symlink HAVE_SYMLINK) CHECK_FUNCTION_EXISTS_GLIBC(sysconf HAVE_SYSCONF) +CHECK_FUNCTION_EXISTS_GLIBC(tcgetattr HAVE_TCGETATTR) +CHECK_FUNCTION_EXISTS_GLIBC(tcsetattr HAVE_TCSETATTR) CHECK_FUNCTION_EXISTS_GLIBC(timegm HAVE_TIMEGM) CHECK_FUNCTION_EXISTS_GLIBC(tzset HAVE_TZSET) CHECK_FUNCTION_EXISTS_GLIBC(unlinkat HAVE_UNLINKAT) diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in index c3c227e6d..ccfcc5be9 100644 --- a/build/cmake/config.h.in +++ b/build/cmake/config.h.in @@ -1175,6 +1175,12 @@ typedef uint64_t uintmax_t; /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_XATTR_H 1 +/* Define to 1 if you have the `tcgetattr' function. */ +#cmakedefine HAVE_TCGETATTR 1 + +/* Define to 1 if you have the `tcsetattr' function. */ +#cmakedefine HAVE_TCSETATTR 1 + /* Define to 1 if you have the `timegm' function. */ #cmakedefine HAVE_TIMEGM 1 diff --git a/configure.ac b/configure.ac index 6c7ed74ef..5e620ae54 100644 --- a/configure.ac +++ b/configure.ac @@ -835,6 +835,7 @@ AC_CHECK_FUNCS([readpassphrase]) AC_CHECK_FUNCS([select setenv setlocale sigaction statfs statvfs]) AC_CHECK_FUNCS([strchr strdup strerror strncpy_s strnlen strrchr symlink]) AC_CHECK_FUNCS([sysconf]) +AC_CHECK_FUNCS([tcgetattr tcsetattr]) AC_CHECK_FUNCS([timegm tzset unlinkat unsetenv utime utimensat utimes vfork]) AC_CHECK_FUNCS([wcrtomb wcscmp wcscpy wcslen wctomb wmemcmp wmemcpy wmemmove]) AC_CHECK_FUNCS([_fseeki64 _get_timezone]) diff --git a/contrib/android/config/android.h b/contrib/android/config/android.h index 0ccb20c4e..00fa4e9fd 100644 --- a/contrib/android/config/android.h +++ b/contrib/android/config/android.h @@ -151,6 +151,8 @@ #define HAVE_SYS_UTSNAME_H 1 #define HAVE_SYS_VFS_H 1 #define HAVE_SYS_WAIT_H 1 +#define HAVE_TCGETATTR 1 +#define HAVE_TCSETATTR 1 #define HAVE_TIME_H 1 #define HAVE_TZSET 1 #define HAVE_UINTMAX_T 1 diff --git a/contrib/android/config/linux_host.h b/contrib/android/config/linux_host.h index 371c6cc48..f0f7ab39c 100644 --- a/contrib/android/config/linux_host.h +++ b/contrib/android/config/linux_host.h @@ -153,6 +153,8 @@ #define HAVE_SYS_VFS_H 1 #define HAVE_SYS_WAIT_H 1 #define HAVE_SYS_XATTR_H 1 +#define HAVE_TCGETATTR 1 +#define HAVE_TCSETATTR 1 #define HAVE_TIMEGM 1 #define HAVE_TIME_H 1 #define HAVE_TZSET 1 diff --git a/contrib/android/config/windows_host.h b/contrib/android/config/windows_host.h index 5210a4db5..da821cc04 100644 --- a/contrib/android/config/windows_host.h +++ b/contrib/android/config/windows_host.h @@ -827,6 +827,12 @@ /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_XATTR_H */ +/* Define to 1 if you have the `tcgetattr' function. */ +/* #undef HAVE_TCGETATTR */ + +/* Define to 1 if you have the `tcsetattr' function. */ +/* #undef HAVE_TCSETATTR */ + /* Define to 1 if you have the `timegm' function. */ /* #undef HAVE_TIMEGM */ diff --git a/libarchive/config_freebsd.h b/libarchive/config_freebsd.h index a1bf0dfe9..5b36e1695 100644 --- a/libarchive/config_freebsd.h +++ b/libarchive/config_freebsd.h @@ -210,6 +210,8 @@ #define HAVE_SYS_TYPES_H 1 #define HAVE_SYS_UTSNAME_H 1 #define HAVE_SYS_WAIT_H 1 +#define HAVE_TCGETATTR 1 +#define HAVE_TCSETATTR 1 #define HAVE_TIMEGM 1 #define HAVE_TIME_H 1 #define HAVE_TZSET 1 diff --git a/libarchive_fe/passphrase.c b/libarchive_fe/passphrase.c index 90fef32d2..527ad2d63 100644 --- a/libarchive_fe/passphrase.c +++ b/libarchive_fe/passphrase.c @@ -119,7 +119,7 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) return (buf); } -#else /* _WIN32 && !__CYGWIN__ */ +#elif defined(HAVE_TCGETATTR) && defined(HAVE_TCSETATTR) #include #include @@ -314,7 +314,13 @@ restart: errno = save_errno; return(nr == -1 ? NULL : buf); } -#endif /* _WIN32 && !__CYGWIN__ */ +#else +static char * +readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) +{ + return (NULL); +} +#endif #endif /* HAVE_READPASSPHRASE */ char * -- 2.47.2