Ticket #105: avahi-ssp-libc-check.patch

File avahi-ssp-libc-check.patch, 2.8 KB (added by tedp, 5 years ago)

Tests for buggy stack-smashing protection

  • configure.ac

     
    5656AC_PROG_MAKE_SET 
    5757AC_PROG_GCC_TRADITIONAL 
    5858 
     59# -fstack-protector 
     60AC_ARG_ENABLE([stack-protector], 
     61    [AS_HELP_STRING([--disable-stack-protector], 
     62        [Disable GCC's/libc's stack-smashing protection])], 
     63    [case "${enableval}" in 
     64         yes) enable_ssp=yes ;; 
     65          no) enable_ssp=no ;; 
     66           *) AC_MSG_ERROR([invalid value ${enableval} for --disable-stack-protector]) ;; 
     67     esac], 
     68    [enable_ssp=yes]) 
     69 
     70if test x"$enable_ssp" = x"yes" && test x"$GCC" != x"yes"; then 
     71    AC_MSG_NOTICE([Disabling stack-smashing protection because compiler is not GCC]) 
     72    enable_ssp=no 
     73fi 
     74 
     75if test x"$enable_ssp" = x"yes"; then 
     76    # Check for broken ssp in libc: http://www.avahi.org/ticket/105 
     77    # libc's brokenness will get in the way regardless of whether -lssp is 
     78    # provided, but provide it anyway (otherwise non-libc ssp would wrongly 
     79    # break here) 
     80 
     81    # Get -lssp if it exists 
     82    GCC_STACK_PROTECT_LIB 
     83 
     84    AC_MSG_CHECKING([whether stack-smashing protection is available]) 
     85    ssp_old_cflags="$CFLAGS" 
     86    ssp_old_ldflags="$LDFLAGS" 
     87    CFLAGS="$CFLAGS -fstack-protector-all -fPIC" 
     88    LDFLAGS="$LDFLAGS -Wl,-z,defs" 
     89    cat confdefs.h > conftest.c 
     90    cat >>conftest.c <<_ACEOF 
     91void test_broken_ssp(c) 
     92    const char *c; 
     93{ 
     94    char arr[[123]], *p; /* beware of possible double-braces if copying this */ 
     95    for (p = arr; *c; ++p) { 
     96        *p = *c; 
     97        ++c; 
     98    } 
     99} 
     100_ACEOF 
     101    rm -f conftest.o 
     102 
     103    if $CC -c $CFLAGS $CPPFLAGS -o conftest.o conftest.c >/dev/null 2>&1; then 
     104        AC_MSG_RESULT([yes]) 
     105        AC_MSG_CHECKING([whether stack-smashing protection is buggy]) 
     106        if $CC -o conftest.so $LDFLAGS -shared conftest.o $LIBS >/dev/null 2>&1; then 
     107            AC_MSG_RESULT([no]) 
     108        else 
     109            AC_MSG_RESULT([yes]) 
     110            enable_ssp=no 
     111        fi 
     112    else 
     113        AC_MSG_RESULT([no]) 
     114    fi 
     115 
     116    rm -f conftest.c conftest.o conftest.so 
     117 
     118    CFLAGS="$ssp_old_cflags" 
     119    LDFLAGS="$ssp_old_ldflags" 
     120fi 
     121 
     122if test x"$enable_ssp" = x"yes"; then 
     123    # Do this the long way so we don't call GCC_STACK_PROTECT_LIB twice 
     124    GCC_STACK_PROTECT_CC 
     125 
     126    AC_LANG_PUSH([C++]) 
     127    GCC_STACK_PROTECT_CXX 
     128    AC_LANG_POP([C++]) 
     129    # XXX: Update the enable_ssp value now for output later? 
     130fi 
     131 
    59132# libtool stuff 
    60133AC_PROG_LIBTOOL 
    61134 
     
    9591032    Group for avahi-autoipd:                   ${AVAHI_AUTOIPD_GROUP} 
    9601033    Enable chroot():                           ${enable_chroot} 
    9611034    Enable Linux inotify:                      ${have_inotify} 
     1035    Enable stack-smashing protection:          ${enable_ssp} 
    9621036" 
    9631037 
    9641038BUILD_DAEMON="no   (You need libdaemon and expat!)"