]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp-server: check dir_fd with assert_return
authorMike Yuan <me@yhndnzj.com>
Fri, 12 Apr 2024 18:47:42 +0000 (02:47 +0800)
committerMike Yuan <me@yhndnzj.com>
Fri, 12 Apr 2024 18:48:52 +0000 (02:48 +0800)
src/libsystemd-network/sd-dhcp-server.c

index 6ec84405d9a279a0b8ad89ee2c0c9f23342cc6f6..427ed63e5b10f2d3d381be97df3380a1c10f2387 100644 (file)
@@ -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)