diff options
author | Eric Blake <eblake@redhat.com> | 2012-10-02 12:22:19 -0600 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2012-10-02 12:28:25 -0600 |
commit | b5b92d84e19423e7de0935abd79a2b7c6df213c2 (patch) | |
tree | 55e0fabc0c02cd256ceda7c458b654e1686c8060 /m4 | |
parent | 064a0470a540a6e98af12c4bc1d1f98b423b4660 (diff) | |
download | gnulib-b5b92d84e19423e7de0935abd79a2b7c6df213c2.tar.gz |
ptsname: reject invalid file descriptors
POSIX left errno undefined on ptsname() failure, although there
has at least been an effort to specify reasonable values to use:
http://www.austingroupbugs.net/view.php?id=503
However, our tests for ptsname and ptsname_r already require errno
to be set to useful values (as in glibc), so it is worth replacing
ptsname on FreeBSD 8.2 in order to get better QoI and pass the test.
* m4/ptsname.m4 (gl_FUNC_PTSNAME): Probe for FreeBSD bug.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Add new witness.
* modules/stdlib (Makefile.am): Replace witness.
* lib/stdlib.in.h (ptsname): Allow for replacement.
* modules/ptsname (configure.ac): Trigger replacement.
* doc/posix-functions/ptsname.texi (ptsname): Document this.
Diffstat (limited to 'm4')
-rw-r--r-- | m4/ptsname.m4 | 22 | ||||
-rw-r--r-- | m4/stdlib_h.m4 | 1 |
2 files changed, 22 insertions, 1 deletions
diff --git a/m4/ptsname.m4 b/m4/ptsname.m4 index ab105be48f..08c9c94d29 100644 --- a/m4/ptsname.m4 +++ b/m4/ptsname.m4 @@ -1,4 +1,4 @@ -# ptsname.m4 serial 2 +# ptsname.m4 serial 3 dnl Copyright (C) 2010-2012 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -14,6 +14,26 @@ AC_DEFUN([gl_FUNC_PTSNAME], AC_CHECK_FUNCS([ptsname]) if test $ac_cv_func_ptsname = no; then HAVE_PTSNAME=0 + else + AC_CACHE_CHECK([whether ptsname sets errno on failure], + [gl_cv_func_ptsname_sets_errno], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM([[#include <errno.h> + ]], [[ + return ptsname (-1) || !errno; + ]])], + [gl_cv_func_ptsname_sets_errno=yes], + [gl_cv_func_ptsname_sets_errno=no], + [case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_ptsname_sets_errno="guessing yes" ;; + # If we don't know, assume the worst. + *) gl_cv_func_ptsname_sets_errno="guessing no" ;; + esac + ])]) + case $gl_cv_func_ptsname_sets_errno in + *no) REPLACE_PTSNAME=1 ;; + esac fi ]) diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index ab43728ace..9c69f2e4d1 100644 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -102,6 +102,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], REPLACE_MALLOC=0; AC_SUBST([REPLACE_MALLOC]) REPLACE_MBTOWC=0; AC_SUBST([REPLACE_MBTOWC]) REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) + REPLACE_PTSNAME=0; AC_SUBST([REPLACE_PTSNAME]) REPLACE_PTSNAME_R=0; AC_SUBST([REPLACE_PTSNAME_R]) REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV]) REPLACE_RANDOM_R=0; AC_SUBST([REPLACE_RANDOM_R]) |