Add configure check for va_copy instead of using #ifdef

This prevents the va_copy compat #define from being used if
sudo_compat.h is somehow included before stdarg.h.
This commit is contained in:
Todd C. Miller
2021-07-25 15:51:23 -06:00
parent b0ae7a566b
commit 4a90deb2a0
4 changed files with 105 additions and 2 deletions

View File

@@ -967,6 +967,9 @@
/* Define to 1 if you have the `vasprintf' function. */
#undef HAVE_VASPRINTF
/* Define to 1 if you have the `va_copy' function. */
#undef HAVE_VA_COPY
/* Define to 1 if you have the `vsnprintf' function. */
#undef HAVE_VSNPRINTF
@@ -1018,6 +1021,9 @@
/* Define to 1 if your crt0.o defines the __progname symbol for you. */
#undef HAVE___PROGNAME
/* Define to 1 if you have the `__va_copy' function. */
#undef HAVE___VA_COPY
/* Define to 1 if you want the hostname to be entered into the log file. */
#undef HOST_IN_LOG

74
configure vendored
View File

@@ -23316,6 +23316,78 @@ fi
esac
LIBS="$OLIBS"
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for va_copy" >&5
printf %s "checking for va_copy... " >&6; }
if test ${sudo_cv_func_va_copy+y}
then :
printf %s "(cached) " >&6
else $as_nop
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <stdarg.h>
va_list ap1, ap2;
int
main (void)
{
va_copy(ap1, ap2);
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
then :
sudo_cv_func_va_copy=yes
else $as_nop
sudo_cv_func_va_copy=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
conftest$ac_exeext conftest.$ac_ext
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $sudo_cv_func_va_copy" >&5
printf "%s\n" "$sudo_cv_func_va_copy" >&6; }
if test "$sudo_cv_func_va_copy" = "yes"; then
printf "%s\n" "#define HAVE_VA_COPY 1" >>confdefs.h
else
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __va_copy" >&5
printf %s "checking for __va_copy... " >&6; }
if test ${sudo_cv_func___va_copy+y}
then :
printf %s "(cached) " >&6
else $as_nop
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <stdarg.h>
va_list ap1, ap2;
int
main (void)
{
__va_copy(ap1, ap2);
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
then :
sudo_cv_func___va_copy=yes
else $as_nop
sudo_cv_func___va_copy=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
conftest$ac_exeext conftest.$ac_ext
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $sudo_cv_func___va_copy" >&5
printf "%s\n" "$sudo_cv_func___va_copy" >&6; }
if test "$sudo_cv_func___va_copy" = "yes"; then
printf "%s\n" "#define HAVE___VA_COPY 1" >>confdefs.h
fi
fi
for ac_func in getprogname
do :
@@ -31782,6 +31854,8 @@ fi

View File

@@ -3226,6 +3226,27 @@ case " $LIBOBJS " in
esac
LIBS="$OLIBS"
dnl
dnl Check for va_copy or __va_copy in stdarg.h
dnl
AC_CACHE_CHECK([for va_copy], sudo_cv_func_va_copy, [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
va_list ap1, ap2;]], [[va_copy(ap1, ap2);]])],
[sudo_cv_func_va_copy=yes], [sudo_cv_func_va_copy=no])
])
if test "$sudo_cv_func_va_copy" = "yes"; then
AC_DEFINE(HAVE_VA_COPY)
else
AC_CACHE_CHECK([for __va_copy], sudo_cv_func___va_copy, [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
va_list ap1, ap2;]], [[__va_copy(ap1, ap2);]])],
[sudo_cv_func___va_copy=yes], [sudo_cv_func___va_copy=no])
])
if test "$sudo_cv_func___va_copy" = "yes"; then
AC_DEFINE(HAVE___VA_COPY)
fi
fi
dnl
dnl Check for getprogname()/setprogname() or __progname
dnl
@@ -5128,6 +5149,8 @@ AH_TEMPLATE(HAVE_SSL_CTX_SET_MIN_PROTO_VERSION, [Define to 1 if you have the `SS
AH_TEMPLATE(HAVE_SSL_CTX_SET_CIPHERSUITES, [Define to 1 if you have the `SSL_CTX_set_ciphersuites' function or macro.])
AH_TEMPLATE(SUDOERS_LOG_CLIENT, [Define to 1 to compile support for sudo_logsrvd in the sudoers plugin.])
AH_TEMPLATE(HAVE_FALLTHROUGH_ATTRIBUTE, [Define to 1 if the compiler supports the fallthrough attribute.])
AH_TEMPLATE(HAVE_VA_COPY, [Define to 1 if you have the `va_copy' function.])
AH_TEMPLATE(HAVE___VA_COPY, [Define to 1 if you have the `__va_copy' function.])
dnl
dnl Bits to copy verbatim into config.h.in

View File

@@ -91,8 +91,8 @@
/*
* Pre-C99 compilers may lack a va_copy macro.
*/
#ifndef va_copy
# ifdef __va_copy
#ifndef HAVE_VA_COPY
# ifdef HAVE___VA_COPY
# define va_copy(d, s) __va_copy(d, s)
# else
# define va_copy(d, s) memcpy(&(d), &(s), sizeof(d));