x_ac_printf_null.m4 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ##*****************************************************************************
  2. # AUTHOR:
  3. # Morris Jette <jette1@llnl.gov>
  4. #
  5. # SYNOPSIS:
  6. # X_AC_PRINTF_NULL
  7. #
  8. # DESCRIPTION:
  9. # Test that printf("%s\n", NULL); does not result in invalid memory
  10. # reference. This is a known issue in Open Solaris version 118 and
  11. # some other operating systems. The potential for this problem exists
  12. # in hundreds of places in the SLURM code, so the ideal place to
  13. # address it is in the underlying print functions.
  14. #
  15. # A good description of the problem can be found here:
  16. # http://arc.opensolaris.org/caselog/PSARC/2008/403/20080625_darren.moffat
  17. #
  18. # Here is an excerpt from that document:
  19. # "The current behavior of the printf(3C) family of functions in libc when
  20. # passed a NULL value for a string format is undefined and usually
  21. # results in a SEGV and crashed application.
  22. #
  23. # The workaround to applications written to depend on this behavior is to
  24. # LD_PRELOAD=/usr/lib/0@0.so.1 (or the 64 bit equivalent). The
  25. # workaround isn't always easy to apply (or it is too late data has been
  26. # lost or corrupted by that point)."
  27. #
  28. # In the case of SLURM, setting LD_PRELOAD to the appropriate value before
  29. # building the code or running any applications will fix the problem. We
  30. # expect to release a version of SLURM supporting OpenSolaris about the same
  31. # as a version of OpenSolaris with this problem fixed is released, so the
  32. # use of LD_PRELOAD will be temporary.
  33. ##*****************************************************************************
  34. AC_DEFUN([X_AC_PRINTF_NULL], [
  35. AC_MSG_CHECKING([for support of printf("%s", NULL)])
  36. AC_RUN_IFELSE([AC_LANG_PROGRAM([
  37. #include <stdio.h>
  38. #include <stdlib.h>],
  39. [[ char tmp[8]; char *n=NULL; snprintf(tmp,8,"%s",n); exit(0); ]])],
  40. printf_null_ok=yes,
  41. printf_null_ok=no,
  42. printf_null_ok=yes)
  43. case "$host" in
  44. *solaris*) have_solaris=yes ;;
  45. *) have_solaris=no ;;
  46. esac
  47. if test "$printf_null_ok" = "no" -a "$have_solaris" = "yes" -a -d /usr/lib64/0@0.so.1; then
  48. AC_MSG_ERROR([printf("%s", NULL) results in abort, upgrade to OpenSolaris release 119 or set LD_PRELOAD=/usr/lib64/0@0.so.1])
  49. elif test "$printf_null_ok" = "no" -a "$have_solaris" = "yes" -a -d /usr/lib/0@0.so.1; then
  50. AC_MSG_ERROR([printf("%s", NULL) results in abort, upgrade to OpenSolaris release 119 or set LD_PRELOAD=/usr/lib/0@0.so.1])
  51. elif test "$printf_null_ok" = "no" -a "$have_solaris" = "yes"; then
  52. AC_MSG_ERROR([printf("%s", NULL) results in abort, upgrade to OpenSolaris release 119])
  53. elif test "$printf_null_ok" = "no"; then
  54. AC_MSG_ERROR([printf("%s", NULL) results in abort])
  55. else
  56. AC_MSG_RESULT([yes])
  57. fi
  58. ])