From: Yu Watanabe Date: Fri, 13 Jun 2025 15:27:06 +0000 (+0900) Subject: sd-dhcp-server: reopen fd only when it is valid X-Git-Tag: v258-rc1~303^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98b02dd7e73fc42676537dab885c70c45b0375fc;p=thirdparty%2Fsystemd.git sd-dhcp-server: reopen fd only when it is valid Fixes a bug in 11b88419ae0004547a0724aa459ddcb5d243f25c. --- diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index 099362d1ae3..335f01f1645 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -1605,9 +1605,13 @@ 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 = fd_reopen(dir_fd, O_CLOEXEC | O_DIRECTORY | O_PATH); - if (fd < 0) - return fd; + _cleanup_close_ int fd = AT_FDCWD; /* Unlike our usual coding style, AT_FDCWD needs to be set, + * to pass a 'valid' fd. */ + if (dir_fd >= 0) { + fd = fd_reopen(dir_fd, O_CLOEXEC | O_DIRECTORY | O_PATH); + if (fd < 0) + return fd; + } r = free_and_strdup(&server->lease_file, path); if (r < 0)