Browse Source

[core] store fd in srv->stdin_fd during setup

(pedantic; no impact)

upon error, server will exit, so the impact of momentarily leaking fd
has no impact.  This commit holds the fd in srv->stdin_fd to address
Coverity warning about leaking fd when using server.bind = "/dev/stdin"
personal/stbuehler/ci-build
Glenn Strauss 1 year ago
parent
commit
ea58cc6f3f
  1. 1
      src/base.h
  2. 13
      src/server.c

1
src/base.h

@ -188,6 +188,7 @@ struct server {
uid_t uid;
gid_t gid;
pid_t pid;
int stdin_fd;
};

13
src/server.c

@ -249,6 +249,7 @@ static server *server_init(void) {
srv->loadavg[0] = 0.0;
srv->loadavg[1] = 0.0;
srv->loadavg[2] = 0.0;
srv->stdin_fd = -1;
return srv;
}
@ -258,6 +259,9 @@ static void server_free(server *srv) {
if (oneshot_fd > 0) {
close(oneshot_fd);
}
if (srv->stdin_fd >= 0) {
close(srv->stdin_fd);
}
#define CLEAN(x) \
buffer_free(srv->x);
@ -714,7 +718,6 @@ static int server_main_setup (server * const srv, int argc, char **argv) {
#ifdef HAVE_FORK
int parent_pipe_fd = -1;
#endif
int stdin_fd = -1;
#ifdef HAVE_GETUID
i_am_root = (0 == getuid());
@ -833,8 +836,9 @@ static int server_main_setup (server * const srv, int argc, char **argv) {
}
if (srv->srvconf.bindhost && buffer_is_equal_string(srv->srvconf.bindhost, CONST_STR_LEN("/dev/stdin"))) {
stdin_fd = dup(STDIN_FILENO);
if (stdin_fd <= STDERR_FILENO) {
if (-1 == srv->stdin_fd)
srv->stdin_fd = dup(STDIN_FILENO);
if (srv->stdin_fd <= STDERR_FILENO) {
log_error(srv->errh, __FILE__, __LINE__,
"Invalid fds at startup");
return -1;
@ -981,9 +985,10 @@ static int server_main_setup (server * const srv, int argc, char **argv) {
}
/* we need root-perms for port < 1024 */
if (0 != network_init(srv, stdin_fd)) {
if (0 != network_init(srv, srv->stdin_fd)) {
return -1;
}
srv->stdin_fd = -1;
if (i_am_root) {
#ifdef HAVE_PWD_H

Loading…
Cancel
Save