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.
It's required by C89, but deprecated in C99, and removed in C11 -- and
glibc follows C11 by removing the declaration if you're asking for that
standard version. (Which is fun since libstdc++ needs it if you're
asking for a new-enough C++, and was the cause of a bunch of scrambling
earlier this year.) So I think this should be changed instead to only
"#undef gets" and then "_GL_WARN_ON_USE" if C11 is in use.
Not according to C Standards, but this is what I did to circumnavigate
the gets removal problem:
The patch changes stdio.h so that even in C11 gets() is defined, but
adds __attribute__ ((error("gets() is dangerous. Don't use it."))) to
both gets() in stdio.h and bits/stdio2.h.
The advantage from my point of view is that there is no "not defined"
error in the various packages trying to throw a usage warning but the
build errors out when gets() is actually used, with or without FORTIFY.
I was kind of worried, how many packages still use gets() but I built
quite a lot of blfs without any problems:
alsa-lib-1.0.24.1
alsa-utils-1.0.24.2
apache-ant-1.8.2
archive-zip-1.30
at-spi2-atk-2.5.3
at-spi2-core-2.5.3
atk-2.5.3
babl-0.1.10
boost-1.50.0
cairo-1.12.2
cdrdao-1.2.2
cdrtools-2.01
clucene-0.9.21b
cmake-2.8.8-graphic
cmake-2.8.8-text
cpio-2.11
cups-1.5.2
curl-7.25.0
cyrus-sasl-2.1.25
dbus-1.5.10
dbus-glib-0.98
docbook-xml-4.5
docbook-xsl-doc-1.76.1
dvd+rw-tools-7.1
epdfview-0.1.8
exiv2-0.22
expat-2.0.1
faac-1.28
faad2-2.7
ffmpeg-0.10
firefox-13.0.1
flac-1.2.1
fluxbox-1.3.2
fontconfig-2.8.0
freeglut-2.8.0
freetype-2.4.9
gdb-7.4.1
gdk-pixbuf-2.26.1
gegl-0.2.0
giflib-4.1.6
gimp-2.8.0
git-0.99.6
glib-2.33.3
gnutls-3.0.8
gperf-3.0.4
gpgme-1.3.1
gpm-1.20.6
gstreamer-0.10.35
gstreamer-plugins-base-0.10.35
gtk+-2.24.10
gtk+-3.5.6
gtk-iconthemes
icedtea-web-1.2
icu-49.1.1
imlib2-1.4.5
intltool-0.41.1
iptables-1.4.13
jasper-1.900.1
jpegsrc.v8d
json-c-0.9
lame-3.99.3
lcms-1.19
lcms2-2.3
liba52dec-0.7.4
libao-1.1.0
libarchive-2.8.5
libassuan-2.0.3
libatasmart-0.18
libatomic_ops-1.2
libcroco-0.6.5
libdrm-2.4.33
libdvdcss-1.2.11
libdvdnav-4.2.0
libdvdread-4.2.0
libexif-0.6.20
libffi-3.0.10
libgcrypt-1.5.0
libgpg-error-1.10
libgsf-1.14.23
libical-0.48
libidl-0.8.14
libmad-0.15.1b
libmng-1.0.10
libmpeg2-0.5.1
libogg-1.3.0
liboil-0.3.17
libpcap-1.2.0
libpng-1.5.9
libpthread-stubs-0.3
librsvg-2.36.1
libsamplerate-0.1.8
libsndfile-1.0.25
libtasn1-2.10
libtheora-1.1.1
libusb-1.0.8
libvorbis-1.3.2
libvpx-v1.0.0
libxau-1.0.6
libxcb-1.7
libxdmcp-1.1.0
libxml2-2.7.8
libxp-1.0.1
libxslt-1.1.26
links-2.4-graphic
links-2.4-text
lvm2-2.02.88
makedepend-1.0.3
mesalib-8.0.3
minicom-2.6.1
neon-0.29.6
nettle-2.4
nmap-6.00
nspr-4.9
nss-3.13.3
openjdk-1.7.0.5-bin
openldap-2.4.29
openntpd-3.9p1
openssh-6.0p1
openssl-1.0.1c
orc-0.4.16
oxygen-icons-4.8.4
pango-1.30.0
parted-3.0
pciutils-3.1.8
pcre-8.30
pixman-0.25.6
polkit-0.104
poppler-0.18.1
printproto-1.0.5
pth-2.0.7
pulseaudio-2.0
python-2.7.2
qt-4.8.2
raptor2-2.0.6
rasqal-0.9.28
redland-1.0.15
samba-3.6.4
sane-backends-1.0.22
sdl-1.2.15
sdl_image-1.2.12
sg3-utils-1.33
shared-desktop-ontologies-0.9.0
shared-mime-info-0.91
speex-1.2rc1
sqlite-autoconf-3071100
strace-4.6
talloc-2.0.7
tcpdump-4.2.1
tiff-3.9.5
udev-182
udisks-1.0.4
unzip60
usbutils-004
util-macros-1.15.0
vpnc-0.5.3
wget-1.13.4
which-2.20
wireshark-1.6.3
x264-20120214
xcb-proto-1.6
xcb-util-0.3.8
xcursor-themes-1.0.3
xine-lib-1.2.1
xkeyboard-config-2.0
xml-parser-2.40
xorg-app-7.6-3
xorg-driver-7.6-3
xorg-font-7.6-3
xorg-lib-7.6-3
xorg-proto-7.6-3
xorg-server-1.12.1
xsane-0.998
xterm-279
yasm-1.2.0
zip30
diff -Naur glibc-2.16.0-orig/libio/bits/stdio2.h
glibc-2.16.0/libio/bits/stdio2.h
--- glibc-2.16.0-orig/libio/bits/stdio2.h 2012-06-30 21:12:34.000000000
+0200
+++ glibc-2.16.0/libio/bits/stdio2.h 2012-07-15 18:56:29.894899402 +0200
@@ -224,7 +224,8 @@
#if !defined __USE_ISOC11 \
|| (defined __cplusplus && __cplusplus <= 201103L && !defined __USE_GNU)
-extern char *__gets_chk (char *__str, size_t) __wur;
+extern char *__gets_chk (char *__str, size_t) __wur
+ __attribute__ ((error("gets() is dangerous. Don't use it.")));
extern char *__REDIRECT (__gets_warn, (char *__str), gets)
__wur __warnattr ("please use fgets or getline instead, gets can't "
"specify buffer size");
diff -Naur glibc-2.16.0-orig/libio/stdio.h glibc-2.16.0/libio/stdio.h
--- glibc-2.16.0-orig/libio/stdio.h 2012-06-30 21:12:34.000000000 +0200
+++ glibc-2.16.0/libio/stdio.h 2012-07-15 18:54:12.270126012 +0200
@@ -622,7 +622,7 @@
extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
__wur;
-#if !defined __USE_ISOC11 \
+#if !defined __USE_ISOC11_THIS_IS_NOT_DEFINED \
|| (defined __cplusplus && __cplusplus <= 201103L)
/* Get a newline-terminated string from stdin, removing the newline.
DO NOT USE THIS FUNCTION!! There is no limit on how much it will read.
@@ -635,7 +635,8 @@
This function is a possible cancellation point and therefore not
marked with __THROW. */
-extern char *gets (char *__s) __wur __attribute_deprecated__;
+extern char *gets (char *__s) __wur __attribute_deprecated__
+ __attribute__((error("gets() is dangerous.Don't use it.")));
#endif
__END_NAMESPACE_STD
--
http://linuxfromscratch.org/mailman/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page