Do not leave stdin as descriptor of a failed context

uev_init() leaves the context descriptor at 0 when epoll_create1()
fails.  A following uev_exit() then closes stdin.

Set it to -1 before creating the epoll descriptor.
This commit is contained in:
NefelibateLG authored and Joachim Wiberg committed 2026-11-16 14:54:49 +01:00
1 parent 4792b988a1
commit 05bc6a0830
2 files changed
+22

No files matched your search

+21
View File
@@ -1,5 +1,6 @@
/* Verifies cleanup on failure to set up a context or watcher */
#include "check.h"
#include <sys/resource.h>
/* A failed uev_event_init() must not leak its eventfd */
static void event_init(void)
@@ -21,9 +22,29 @@ static void event_init(void)
close(fd);
}
/* A failed uev_init() must not leave stdin as the context descriptor */
static void ctx_init(void)
{
struct rlimit old, lim;
uev_ctx_t ctx;
int rc;
fail_unless(getrlimit(RLIMIT_NOFILE, &old) == 0);
lim = old;
lim.rlim_cur = 0;
fail_unless(setrlimit(RLIMIT_NOFILE, &lim) == 0);
rc = uev_init(&ctx);
fail_unless(setrlimit(RLIMIT_NOFILE, &old) == 0);
fail_unless(rc == -1);
fail_unless(ctx.fd == -1);
}
int main(void)
{
event_init();
ctx_init();
return 0;
}