fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers
Log | Files | Refs | README | LICENSE

commit 28d61f4202a73fa39d07774c66e1404858adfee9
parent 79447cbb8dc30e2335e3bb186de8e1172b3dff90
Author: jvoisin <julien.voisin@dustri.org>
Date:   Thu, 22 Jun 2023 18:33:53 +0200

Add a test for `poll`

Diffstat:
Minclude/poll.h | 4++--
Mtests/Makefile | 1+
Atests/test_poll.c | 14++++++++++++++
3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/include/poll.h b/include/poll.h @@ -32,7 +32,7 @@ extern "C" { _FORTIFY_FN(poll) int poll(struct pollfd *__f, nfds_t __n, int __s) { - __typeof__(sizeof 0) __b = __bos(__f, 0); + size_t __b = __bos(__f, 0); if (__n > __b / sizeof(struct pollfd)) __builtin_trap(); @@ -44,7 +44,7 @@ _FORTIFY_FN(poll) int poll(struct pollfd *__f, nfds_t __n, int __s) _FORTIFY_FN(ppoll) int ppoll(struct pollfd *__f, nfds_t __n, const struct timespec *__s, const sigset_t *__m) { - __typeof__(sizeof 0) __b = __bos(__f, 0); + size_t __b = __bos(__f, 0); if (__n > __b / sizeof(struct pollfd)) __builtin_trap(); diff --git a/tests/Makefile b/tests/Makefile @@ -31,6 +31,7 @@ TARGETS=test_memcpy_static_write \ test_stpncpy_overwrite_under \ test_stpncpy_static_write \ test_getcwd \ + test_poll \ .SILENT: diff --git a/tests/test_poll.c b/tests/test_poll.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <poll.h> + +int main(int argc, char** argv) { + struct pollfd buffer[12] = {0}; + + CHK_FAIL_START + poll(buffer, 14, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +}