off-by-one error in epoll_recalc; reported by Victor Goya

svn:r1124
This commit is contained in:
Niels Provos 2009-03-12 17:03:21 +00:00
parent 4cf8138b8f
commit f06b29b9e2
3 changed files with 61 additions and 1 deletions

View File

@ -5,6 +5,7 @@ Changes in 1.4.10-stable:
o support compilation on Haiku
o fix signal processing when a signal callback delivers a signal; from Alexander Drozdov
o const-ify some arguments to evdns functions.
o off-by-one error in epoll_recalc; reported by Victor Goya
Changes in 1.4.9-stable:
o event_add would not return error for some backends; from Dean McNamee

View File

@ -166,7 +166,7 @@ epoll_recalc(struct event_base *base, void *arg, int max)
{
struct epollop *epollop = arg;
if (max > epollop->nfds) {
if (max >= epollop->nfds) {
struct evepoll *fds;
int nfds;

View File

@ -95,6 +95,9 @@ simple_read_cb(int fd, short event, void *arg)
char buf[256];
int len;
if (arg == NULL)
return;
len = read(fd, buf, sizeof(buf));
if (len) {
@ -113,6 +116,9 @@ simple_write_cb(int fd, short event, void *arg)
{
int len;
if (arg == NULL)
return;
len = write(fd, TEST1, strlen(TEST1) + 1);
if (len == -1)
test_ok = 0;
@ -303,6 +309,57 @@ cleanup_test(void)
return (0);
}
static void
test_registerfds(void)
{
int i, j;
int pair[2];
struct event read_evs[512];
struct event write_evs[512];
struct event_base *base = event_base_new();
fprintf(stdout, "Testing register fds: ");
for (i = 0; i < 512; ++i) {
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
/* run up to the limit of file descriptors */
break;
}
event_set(&read_evs[i], pair[0],
EV_READ|EV_PERSIST, simple_read_cb, NULL);
event_base_set(base, &read_evs[i]);
event_add(&read_evs[i], NULL);
event_set(&write_evs[i], pair[1],
EV_WRITE|EV_PERSIST, simple_write_cb, NULL);
event_base_set(base, &write_evs[i]);
event_add(&write_evs[i], NULL);
/* just loop once */
event_base_loop(base, EVLOOP_ONCE);
}
/* now delete everything */
for (j = 0; j < i; ++j) {
event_del(&read_evs[j]);
event_del(&write_evs[j]);
#ifndef WIN32
close(read_evs[j].ev_fd);
close(write_evs[j].ev_fd);
#else
CloseHandle((HANDLE)read_evs[j].ev_fd);
CloseHandle((HANDLE)write_evs[j].ev_fd);
#endif
/* just loop once */
event_base_loop(base, EVLOOP_ONCE);
}
event_base_free(base);
fprintf(stdout, "OK\n");
}
static void
test_simpleread(void)
{
@ -1570,6 +1627,8 @@ main (int argc, char **argv)
/* Initalize the event library */
global_base = event_init();
test_registerfds();
test_evutil_strtoll();
/* use the global event base and need to be called first */