From: Michael Tremer Date: Wed, 1 Nov 2023 16:43:08 +0000 (+0000) Subject: jail: Fix more fd checks X-Git-Tag: 0.9.30~1334 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dd2d7dbbbec1f57a606f8c1042ef3644efe4d99f;p=pakfire.git jail: Fix more fd checks Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index b13ff205a..ebcb6f31a 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -519,7 +519,7 @@ static int pakfire_jail_create_timer(struct pakfire_jail* jail) { return fd; ERROR: - if (fd > 0) + if (fd >= 0) close(fd); return -1; @@ -689,7 +689,7 @@ static int pakfire_jail_stream_stdin(struct pakfire_jail* jail, close(fd); // Reset the file-descriptor so it won't be closed again later - ctx->pipes.stdin[1] = 0; + ctx->pipes.stdin[1] = -1; // Report success r = 0; @@ -710,7 +710,7 @@ static int pakfire_jail_setup_pipe(struct pakfire_jail* jail, int (*fds)[2], con static void pakfire_jail_close_pipe(struct pakfire_jail* jail, int fds[2]) { for (unsigned int i = 0; i < 2; i++) - if (fds[i]) + if (fds[i] >= 0) close(fds[i]); } @@ -1022,11 +1022,11 @@ static int pakfire_jail_wait(struct pakfire_jail* jail, struct pakfire_jail_exec } ERROR: - if (epollfd > 0) + if (epollfd >= 0) close(epollfd); - if (timerfd > 0) + if (timerfd >= 0) close(timerfd); - if (signalfd > 0) + if (signalfd >= 0) close(signalfd); return r; @@ -2051,7 +2051,7 @@ ERROR: pakfire_jail_close_pipe(jail, ctx.pipes.stdin); pakfire_jail_close_pipe(jail, ctx.pipes.stdout); pakfire_jail_close_pipe(jail, ctx.pipes.stderr); - if (ctx.pidfd) + if (ctx.pidfd >= 0) close(ctx.pidfd); pakfire_jail_close_pipe(jail, ctx.pipes.log_INFO); pakfire_jail_close_pipe(jail, ctx.pipes.log_ERROR);