Skip to content

Commit

Permalink
If cross-compiling with a C99 compiler, assume snprintf is compliant.
Browse files Browse the repository at this point in the history
This is a better default than assuming it is not compliant (the
previous behavior) when cross-compiling.  These days it is rare for
sudo to be built on pre-C99 systems.  GitHub issue #969
  • Loading branch information
millert committed Jul 3, 2024
1 parent fc051ce commit 920710b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -24902,6 +24902,20 @@ 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

fi
if test X"$ac_cv_have_working_snprintf$ac_cv_have_working_vsnprintf" = X"yesyes"
then :
Expand Down
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3053,6 +3053,14 @@ AS_IF([test X"$sudo_mktemp" = X"yes"], [
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"], [

This comment has been minimized.

Copy link
@egtvedt

egtvedt Sep 2, 2024

I'm trying to cross compile sudo 1.9.16, and run into linker issues due to undefined reference to `sudo_snprintf'.

Looking at the generated configure script, the order of this cross compilation check might be wrong?

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_working_vsnprintf" >&5
printf "%s\n" "$ac_cv_have_working_vsnprintf" >&6; }
if test x$ac_cv_have_working_snprintf$ac_cv_have_working_vsnprintf != "xyesyes"; then
  case " $LIBOBJS " in
  *" snprintf.$ac_objext "* ) ;;
  *) LIBOBJS="$LIBOBJS snprintf.$ac_objext"
 ;;
esac

  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Replacing missing/broken (v)snprintf() with sudo's version." >&5
printf "%s\n" "$as_me: WARNING: Replacing missing/broken (v)snprintf() with sudo's version." >&2;}

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

So the PREFER_PORTABLE_SNPRINTF symbol is set, but later also functional (v)snprintf() functions.

# 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
])
])
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()
AC_CHECK_FUNCS([asprintf], [], [
Expand Down

0 comments on commit 920710b

Please sign in to comment.