From 3c321488bc0a1281985a0238df07ea89fb2ad59a Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 13 Apr 2024 02:47:42 +0800 Subject: [PATCH] sd-dhcp-server: check dir_fd with assert_return --- src/libsystemd-network/sd-dhcp-server.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index 6ec84405d9a..427ed63e5b1 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -1592,6 +1592,7 @@ int sd_dhcp_server_set_lease_file(sd_dhcp_server *server, int dir_fd, const char int r; assert_return(server, -EINVAL); + assert_return(!path || (dir_fd >= 0 || dir_fd == AT_FDCWD), -EBADF); assert_return(!sd_dhcp_server_is_running(server), -EBUSY); if (!path) { @@ -1604,9 +1605,6 @@ int sd_dhcp_server_set_lease_file(sd_dhcp_server *server, int dir_fd, const char if (!path_is_safe(path)) return -EINVAL; - if (dir_fd < 0 && dir_fd != AT_FDCWD) - return -EBADF; - _cleanup_close_ int fd = -EBADF; fd = fd_reopen(dir_fd, O_CLOEXEC | O_DIRECTORY | O_PATH); if (fd < 0)