From: deraadt Date: Tue, 23 Nov 2021 01:14:26 +0000 (+0000) Subject: A weird little test which can expose buggy return value conditions in poll() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=42ebeb7d780d20b60531b537dc2393a21e3add6d;p=openbsd A weird little test which can expose buggy return value conditions in poll() --- diff --git a/regress/sys/kern/poll/Makefile b/regress/sys/kern/poll/Makefile index 3b87d79221c..e2310597121 100644 --- a/regress/sys/kern/poll/Makefile +++ b/regress/sys/kern/poll/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.2 2021/11/21 06:21:01 visa Exp $ +# $OpenBSD: Makefile,v 1.3 2021/11/23 01:14:26 deraadt Exp $ -PROGS= poll_close pollnval +PROGS= poll_close pollnval pollretval LDADD= -lpthread WARNINGS= yes diff --git a/regress/sys/kern/poll/pollretval.c b/regress/sys/kern/poll/pollretval.c new file mode 100644 index 00000000000..9d2d4cae0f3 --- /dev/null +++ b/regress/sys/kern/poll/pollretval.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include + +int +main() +{ + struct pollfd pfd[100]; + int i, r, r2 = 0; + + for (i = 0; i < 100; i++) { + pfd[i].fd = 0; + pfd[i].events = arc4random() % 0x177; + } + + r = poll(pfd, 100, INFTIM); + + if (r == -1) + errx(1, "poll failed unexpectedly"); + + for (i = 0; i < 100; i++) + if (pfd[i].revents) + r2++; + if (r != r2) + errx(1, "poll return value %d miscounts .revents %d", r, r2); +}