diff options
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | debug/Makefile | 2 | ||||
-rw-r--r-- | debug/Versions | 3 | ||||
-rw-r--r-- | debug/poll_chk.c | 29 | ||||
-rw-r--r-- | debug/ppoll_chk.c | 30 | ||||
-rw-r--r-- | debug/tst-chk1.c | 19 | ||||
-rw-r--r-- | include/bits/poll2.h | 1 | ||||
-rw-r--r-- | include/sys/poll.h | 1 | ||||
-rw-r--r-- | io/bits/poll2.h | 78 | ||||
-rw-r--r-- | io/ppoll.c | 3 | ||||
-rw-r--r-- | io/sys/poll.h | 6 | ||||
-rw-r--r-- | sysdeps/mach/hurd/ppoll.c | 3 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/ppoll.c | 3 |
14 files changed, 190 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog index 776323a0e3..85b842008a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2012-01-08 Ulrich Drepper <drepper@gmail.com> + * debug/Makefile (routines): Add poll_chk and ppoll_chk. + * debug/Versions: Export __pool_chk and __ppoll_chk from libc for + GLIBC_2.16. + * debug/tst-chk1.c: Add poll and ppoll tests. + * io/sys/poll.h: Include bits/poll2.h for _FORTIFY_SOURCE. + * include/sys/poll.h: Add hidden proto for ppoll. + * sysdeps/unix/sysv/linux/ppoll.c: Add hidden def. + * sysdeps/mach/hurd/ppoll.c: Likewise. + * io/ppoll.c: Likewise. + * debug/poll_chk.c: New file. + * debug/ppoll_chk.c: New file. + * include/bits/poll2.h: New file. + * io/bits/poll2.h: New file. + [BZ #1350] * math/complex.h (CMPLX, CMPLXF, CMPLXL): Define. diff --git a/NEWS b/NEWS index 01f55dcb29..7d5de0ad1d 100644 --- a/NEWS +++ b/NEWS @@ -36,6 +36,9 @@ Version 2.16 * Support for the IA-64 is removed and could live in ports. * Remove support for anything but ELF binary format + +* Checking versions of poll, ppoll added. + Implemented by Ulrich Drepper. Version 2.15 diff --git a/debug/Makefile b/debug/Makefile index 579fce66da..dca4e97615 100644 --- a/debug/Makefile +++ b/debug/Makefile @@ -44,7 +44,7 @@ routines = backtrace backtracesyms backtracesymsfd noophooks \ wcstombs_chk asprintf_chk vasprintf_chk dprintf_chk \ vdprintf_chk obprintf_chk \ longjmp_chk ____longjmp_chk \ - fdelt_chk \ + fdelt_chk poll_chk ppoll_chk \ stack_chk_fail fortify_fail \ $(static-only-routines) static-only-routines := warning-nop stack_chk_fail_local diff --git a/debug/Versions b/debug/Versions index 3db4a2955f..c1722fab20 100644 --- a/debug/Versions +++ b/debug/Versions @@ -52,6 +52,9 @@ libc { GLIBC_2.15 { __fdelt_chk; __fdelt_warn; } + GLIBC_2.16 { + __poll_chk; __ppoll_chk; + } GLIBC_PRIVATE { __fortify_fail; } diff --git a/debug/poll_chk.c b/debug/poll_chk.c new file mode 100644 index 0000000000..df795e8ae9 --- /dev/null +++ b/debug/poll_chk.c @@ -0,0 +1,29 @@ +/* Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sys/poll.h> + + +int +__poll_chk (struct pollfd *fds, nfds_t nfds, int timeout, __SIZE_TYPE__ fdslen) +{ + if (fdslen / sizeof (*fds) < nfds) + __chk_fail (); + + return __poll (fds, nfds, timeout); +} diff --git a/debug/ppoll_chk.c b/debug/ppoll_chk.c new file mode 100644 index 0000000000..63f922321c --- /dev/null +++ b/debug/ppoll_chk.c @@ -0,0 +1,30 @@ +/* Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sys/poll.h> + + +int +__ppoll_chk (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, + const __sigset_t *ss, __SIZE_TYPE__ fdslen) +{ + if (fdslen / sizeof (*fds) < nfds) + __chk_fail (); + + return ppoll (fds, nfds, timeout, ss); +} diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c index 7f0186e706..2593ab9f18 100644 --- a/debug/tst-chk1.c +++ b/debug/tst-chk1.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004,2005,2006,2007,2008,2011 Free Software Foundation, Inc. +/* Copyright (C) 2004-2008,2011,2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek <jakub@redhat.com>, 2004. @@ -29,6 +29,7 @@ #include <string.h> #include <unistd.h> #include <wchar.h> +#include <sys/poll.h> #include <sys/select.h> #include <sys/socket.h> #include <sys/un.h> @@ -1476,5 +1477,21 @@ do_test (void) CHK_FAIL_END #endif + struct pollfd fds[1]; + fds[0].fd = STDOUT_FILENO; + fds[0].events = POLLOUT; + poll (fds, 1, 0); +#if __USE_FORTIFY_LEVEL >= 1 + CHK_FAIL_START + poll (fds, 2, 0); + CHK_FAIL_END +#endif + ppoll (fds, 1, NULL, NULL); +#if __USE_FORTIFY_LEVEL >= 1 + CHK_FAIL_START + ppoll (fds, 2, NULL, NULL); + CHK_FAIL_END +#endif + return ret; } diff --git a/include/bits/poll2.h b/include/bits/poll2.h new file mode 100644 index 0000000000..51a0812c1e --- /dev/null +++ b/include/bits/poll2.h @@ -0,0 +1 @@ +#include "../../io/bits/poll2.h" diff --git a/include/sys/poll.h b/include/sys/poll.h index 7d12e1c9be..4285eee55b 100644 --- a/include/sys/poll.h +++ b/include/sys/poll.h @@ -4,5 +4,6 @@ extern int __poll (struct pollfd *__fds, unsigned long int __nfds, int __timeout); libc_hidden_proto (__poll) +libc_hidden_proto (ppoll) #endif diff --git a/io/bits/poll2.h b/io/bits/poll2.h new file mode 100644 index 0000000000..7a9dd8a30b --- /dev/null +++ b/io/bits/poll2.h @@ -0,0 +1,78 @@ +/* Checking macros for poll functions. + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _SYS_POLL_H +# error "Never include <bits/poll2.h> directly; use <sys/poll.h> instead." +#endif + + +extern int __REDIRECT (__poll_alias, (struct pollfd *__fds, nfds_t __nfds, + int __timeout), poll); +extern int __poll_chk (struct pollfd *__fds, nfds_t __nfds, int __timeout, + __SIZE_TYPE__ __fdslen); +extern int __REDIRECT (__poll_chk_warn, (struct pollfd *__fds, nfds_t __nfds, + int __timeout, __SIZE_TYPE__ __fdslen), + __poll_chk) + __warnattr ("poll called with fds buffer too small file nfds entries"); + +__extern_always_inline int +poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) +{ + if (__bos (__fds) != (__SIZE_TYPE__) -1) + { + if (! __builtin_constant_p (__nfds)) + return __poll_chk (__fds, __nfds, __timeout, __bos (__fds)); + else if (__bos (__fds) / sizeof (*__fds) < __nfds) + return __poll_chk_warn (__fds, __nfds, __timeout, __bos (__fds)); + } + + return __poll_alias (__fds, __nfds, __timeout); +} + + +#ifdef __USE_GNU +extern int __REDIRECT (__ppoll_alias, (struct pollfd *__fds, nfds_t __nfds, + const struct timespec *__timeout, + const __sigset_t *__ss), ppoll); +extern int __ppoll_chk (struct pollfd *__fds, nfds_t __nfds, + const struct timespec *__timeout, + const __sigset_t *__ss, __SIZE_TYPE__ __fdslen); +extern int __REDIRECT (__ppoll_chk_warn, (struct pollfd *__fds, nfds_t __nfds, + const struct timespec *__timeout, + const __sigset_t *__ss, + __SIZE_TYPE__ __fdslen), + __ppoll_chk) + __warnattr ("ppoll called with fds buffer too small file nfds entries"); + +__extern_always_inline int +ppoll (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout, + const __sigset_t *__ss) +{ + if (__bos (__fds) != (__SIZE_TYPE__) -1) + { + if (! __builtin_constant_p (__nfds)) + return __ppoll_chk (__fds, __nfds, __timeout, __ss, __bos (__fds)); + else if (__bos (__fds) / sizeof (*__fds) < __nfds) + return __ppoll_chk_warn (__fds, __nfds, __timeout, __ss, + __bos (__fds)); + } + + return __ppoll_alias (__fds, __nfds, __timeout, __ss); +} +#endif diff --git a/io/ppoll.c b/io/ppoll.c index a035cfeb1f..b161a47b3d 100644 --- a/io/ppoll.c +++ b/io/ppoll.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2006 Free Software Foundation, Inc. +/* Copyright (C) 2006, 2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2006. @@ -73,4 +73,5 @@ ppoll (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, #ifndef ppoll /* __poll handles cancellation. */ LIBC_CANCEL_HANDLED (); +libc_hidden_def (ppoll); #endif diff --git a/io/sys/poll.h b/io/sys/poll.h index a9bd18005a..c0a7e04099 100644 --- a/io/sys/poll.h +++ b/io/sys/poll.h @@ -71,4 +71,10 @@ extern int ppoll (struct pollfd *__fds, nfds_t __nfds, __END_DECLS + +/* Define some inlines helping to catch common problems. */ +#if __USE_FORTIFY_LEVEL > 0 && defined __extern_always_inline +# include <bits/poll2.h> +#endif + #endif /* sys/poll.h */ diff --git a/sysdeps/mach/hurd/ppoll.c b/sysdeps/mach/hurd/ppoll.c index 693bc13839..f8db6f0ef9 100644 --- a/sysdeps/mach/hurd/ppoll.c +++ b/sysdeps/mach/hurd/ppoll.c @@ -1,5 +1,5 @@ /* poll file descriptors. Hurd version. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2012 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -28,3 +28,4 @@ ppoll (struct pollfd *fds, nfds_t nfds, { return _hurd_select (nfds, fds, NULL, NULL, NULL, timeout, sigmask); } +libc_hidden_def (ppoll) diff --git a/sysdeps/unix/sysv/linux/ppoll.c b/sysdeps/unix/sysv/linux/ppoll.c index 14eb3111b9..b331b3a774 100644 --- a/sysdeps/unix/sysv/linux/ppoll.c +++ b/sysdeps/unix/sysv/linux/ppoll.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2006, 2007 Free Software Foundation, Inc. +/* Copyright (C) 2006, 2007, 2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2006. @@ -67,6 +67,7 @@ ppoll (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, return result; } +libc_hidden_def (ppoll) # ifndef __ASSUME_PPOLL # define ppoll static __generic_ppoll |