2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 01:49:11 +00:00

Better test for cross-compiling when checking for C99 snprintf

We want to avoid calling AX_FUNC_SNPRINTF entirely if cross-compiling
since it is not possible to undo the setting of PREFER_PORTABLE_SNPRINTF.
The previous attempt to do this failed to take into account that
PREFER_PORTABLE_SNPRINTF would still be defined.  GitHub issue #969
This commit is contained in:
Todd C. Miller 2024-09-02 17:10:19 -06:00
parent 4751a4d2dd
commit 3e12cacc0f
2 changed files with 34 additions and 20 deletions

41
configure vendored
View File

@ -24790,7 +24790,31 @@ esac
COMPAT_TEST_PROGS="${COMPAT_TEST_PROGS}${COMPAT_TEST_PROGS+ }mktemp_test"
fi
ac_fn_c_check_func "$LINENO" "snprintf" "ac_cv_func_snprintf"
if test X"$ac_cv_build_prog_cc_c99" != X"no" -a X"$cross_compiling" = X"yes"
then :
# If we have a C99 compiler and are cross-compiling, assume
# C99-compliant v?snprintf().
ac_fn_c_check_func "$LINENO" "snprintf" "ac_cv_func_snprintf"
if test "x$ac_cv_func_snprintf" = xyes
then :
printf "%s\n" "#define HAVE_SNPRINTF 1" >>confdefs.h
fi
ac_fn_c_check_func "$LINENO" "vsnprintf" "ac_cv_func_vsnprintf"
if test "x$ac_cv_func_vsnprintf" = xyes
then :
printf "%s\n" "#define HAVE_VSNPRINTF 1" >>confdefs.h
fi
ac_cv_have_working_snprintf="$ac_cv_func_snprintf"
ac_cv_have_working_vsnprintf="$ac_cv_func_vsnprintf"
else case e in #(
e)
# Check for C99-compliant v?snprintf().
ac_fn_c_check_func "$LINENO" "snprintf" "ac_cv_func_snprintf"
if test "x$ac_cv_func_snprintf" = xyes
then :
printf "%s\n" "#define HAVE_SNPRINTF 1" >>confdefs.h
@ -24919,19 +24943,8 @@ printf "%s\n" "$as_me: WARNING: Replacing missing/broken (v)snprintf() with sudo
printf "%s\n" "#define PREFER_PORTABLE_SNPRINTF 1" >>confdefs.h
fi
if test X"$ac_cv_build_prog_cc_c99" != X"no"
then :
# If we have a C99 compiler and are cross-compiling, assume
# C99-compliant v?snprintf().
if test X"$ac_cv_have_working_snprintf$ac_cv_have_working_vsnprintf" = X"crosscross"
then :
ac_cv_have_working_snprintf=yes
ac_cv_have_working_vsnprintf=yes
fi
;;
esac
fi
if test X"$ac_cv_have_working_snprintf$ac_cv_have_working_vsnprintf" = X"yesyes"
then :

View File

@ -3060,14 +3060,15 @@ AS_IF([test X"$sudo_mktemp" = X"yes"], [
SUDO_APPEND_COMPAT_EXP(sudo_mkdtemp sudo_mkdtempat sudo_mkostempsat sudo_mkstemp sudo_mkstemps)
COMPAT_TEST_PROGS="${COMPAT_TEST_PROGS}${COMPAT_TEST_PROGS+ }mktemp_test"
])
AX_FUNC_SNPRINTF
AS_IF([test X"$ac_cv_prog_cc_c99" != X"no"], [
AS_IF([test X"$ac_cv_prog_cc_c99" != X"no" -a X"$cross_compiling" = X"yes"], [
# If we have a C99 compiler and are cross-compiling, assume
# C99-compliant v?snprintf().
AS_IF([test X"$ac_cv_have_working_snprintf$ac_cv_have_working_vsnprintf" = X"crosscross"], [
ac_cv_have_working_snprintf=yes
ac_cv_have_working_vsnprintf=yes
])
AC_CHECK_FUNCS(snprintf vsnprintf)
ac_cv_have_working_snprintf="$ac_cv_func_snprintf"
ac_cv_have_working_vsnprintf="$ac_cv_func_vsnprintf"
], [
# Check for C99-compliant v?snprintf().
AX_FUNC_SNPRINTF
])
AS_IF([test X"$ac_cv_have_working_snprintf$ac_cv_have_working_vsnprintf" = X"yesyes"], [
# System has a C99-compliant v?snprintf(), check for v?asprintf()