1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-03 17:47:28 +03:00

sd-dhcp-server: use close_and_replace (avoid fd leak)

Follow-up for 11b88419ae0004547a0724aa459ddcb5d243f25c

Fixes #32252
This commit is contained in:
Mike Yuan 2024-04-13 02:40:22 +08:00
parent 3c321488bc
commit d2198b3206
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3

View File

@ -1605,8 +1605,7 @@ int sd_dhcp_server_set_lease_file(sd_dhcp_server *server, int dir_fd, const char
if (!path_is_safe(path))
return -EINVAL;
_cleanup_close_ int fd = -EBADF;
fd = fd_reopen(dir_fd, O_CLOEXEC | O_DIRECTORY | O_PATH);
_cleanup_close_ int fd = fd_reopen(dir_fd, O_CLOEXEC | O_DIRECTORY | O_PATH);
if (fd < 0)
return fd;
@ -1614,6 +1613,7 @@ int sd_dhcp_server_set_lease_file(sd_dhcp_server *server, int dir_fd, const char
if (r < 0)
return r;
server->lease_dir_fd = TAKE_FD(fd);
close_and_replace(server->lease_dir_fd, fd);
return 0;
}