mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-24 22:10:13 +00:00
Add checking versions of poll and ppoll
This commit is contained in:
parent
15cfed3f93
commit
d9a216c037
14
ChangeLog
14
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.
|
||||
|
||||
|
3
NEWS
3
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
|
||||
|
||||
|
@ -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
|
||||
|
@ -52,6 +52,9 @@ libc {
|
||||
GLIBC_2.15 {
|
||||
__fdelt_chk; __fdelt_warn;
|
||||
}
|
||||
GLIBC_2.16 {
|
||||
__poll_chk; __ppoll_chk;
|
||||
}
|
||||
GLIBC_PRIVATE {
|
||||
__fortify_fail;
|
||||
}
|
||||
|
29
debug/poll_chk.c
Normal file
29
debug/poll_chk.c
Normal file
@ -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);
|
||||
}
|
30
debug/ppoll_chk.c
Normal file
30
debug/ppoll_chk.c
Normal file
@ -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);
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
1
include/bits/poll2.h
Normal file
1
include/bits/poll2.h
Normal file
@ -0,0 +1 @@
|
||||
#include "../../io/bits/poll2.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
|
||||
|
78
io/bits/poll2.h
Normal file
78
io/bits/poll2.h
Normal file
@ -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
|
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user