Gnulib intentionally does not have a gets module, and now that C11 and glibc have dropped it, we should be more proactive about warning any user on a platform that still has a declaration of this dangerous interface.
* m4/stdio_h.m4 (gl_STDIO_H, gl_STDIO_H_DEFAULTS): Drop gets support. * lib/stdio.in.h (gets): Make warning occur in more places. Reported by Christer Solskogen. Signed-off-by: Eric Blake <[email protected]> --- Any thoughts before I push this? ChangeLog | 7 +++++++ lib/stdio.in.h | 20 ++++---------------- m4/stdio_h.m4 | 10 ++++------ 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index d74544a..3ef5d84 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2012-03-29 Eric Blake <[email protected]> + + stdio: don't assume gets any more + * m4/stdio_h.m4 (gl_STDIO_H, gl_STDIO_H_DEFAULTS): Drop gets + support. + * lib/stdio.in.h (gets): Make warning occur in more places. + 2012-03-25 Bruno Haible <[email protected]> Tests for module 'localeconv'. diff --git a/lib/stdio.in.h b/lib/stdio.in.h index aa7b599..ac150b1 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -698,26 +698,14 @@ _GL_WARN_ON_USE (getline, "getline is unportable - " # endif #endif -#if @GNULIB_GETS@ -# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef gets -# define gets rpl_gets -# endif -_GL_FUNCDECL_RPL (gets, char *, (char *s) _GL_ARG_NONNULL ((1))); -_GL_CXXALIAS_RPL (gets, char *, (char *s)); -# else -_GL_CXXALIAS_SYS (gets, char *, (char *s)); -# undef gets -# endif -_GL_CXXALIASWARN (gets); /* It is very rare that the developer ever has full control of stdin, - so any use of gets warrants an unconditional warning. Assume it is - always declared, since it is required by C89. */ + so any use of gets warrants an unconditional warning; besides, C11 + removed it. */ +#undef gets +#if HAVE_RAW_DECL_GETS _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); #endif - #if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@ struct obstack; /* Grow an obstack with formatted output. Return the number of diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4 index 1973e8d..b03393b 100644 --- a/m4/stdio_h.m4 +++ b/m4/stdio_h.m4 @@ -1,4 +1,4 @@ -# stdio_h.m4 serial 40 +# stdio_h.m4 serial 41 dnl Copyright (C) 2007-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, @@ -18,7 +18,6 @@ AC_DEFUN([gl_STDIO_H], GNULIB_GETC=1 GNULIB_GETCHAR=1 GNULIB_FGETS=1 - GNULIB_GETS=1 GNULIB_FREAD=1 dnl This ifdef is necessary to avoid an error "missing file lib/stdio-read.c" dnl "expected source file, required through AC_LIBSOURCES, not found". It is @@ -72,10 +71,10 @@ AC_DEFUN([gl_STDIO_H], dnl Check for declarations of anything we want to poison if the dnl corresponding gnulib module is not in use, and which is not - dnl guaranteed by C89. + dnl guaranteed by both C89 and C11. gl_WARN_ON_USE_PREPARE([[#include <stdio.h> - ]], [dprintf fpurge fseeko ftello getdelim getline pclose popen renameat - snprintf tmpfile vdprintf vsnprintf]) + ]], [dprintf fpurge fseeko ftello getdelim getline gets pclose popen + renameat snprintf tmpfile vdprintf vsnprintf]) ]) AC_DEFUN([gl_STDIO_MODULE_INDICATOR], @@ -113,7 +112,6 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS], GNULIB_GETCHAR=0; AC_SUBST([GNULIB_GETCHAR]) GNULIB_GETDELIM=0; AC_SUBST([GNULIB_GETDELIM]) GNULIB_GETLINE=0; AC_SUBST([GNULIB_GETLINE]) - GNULIB_GETS=0; AC_SUBST([GNULIB_GETS]) GNULIB_OBSTACK_PRINTF=0; AC_SUBST([GNULIB_OBSTACK_PRINTF]) GNULIB_OBSTACK_PRINTF_POSIX=0; AC_SUBST([GNULIB_OBSTACK_PRINTF_POSIX]) GNULIB_PCLOSE=0; AC_SUBST([GNULIB_PCLOSE]) -- 1.7.7.6
