From ad2a36f2c70473c268110bad4444958b4ff32aae Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 21 Jan 2026 19:04:36 +0100 Subject: [PATCH] Check dirfd result before using it --- cmdline/unix.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmdline/unix.c b/cmdline/unix.c index 3bfc948e..24b0b7b2 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -506,12 +506,18 @@ static int devuuid_dev(uint64_t device, char* uuid, size_t uuid_size) return -1; } + int dir_fd = dirfd(d); + if (dir_fd == -1) { + log_tag("uuid:by-uuid:%u:%u: dirfd(/dev/disk/by-uuid) failed, %s\n", major(device), minor(device), strerror(errno)); + return -1; + } + while ((dd = readdir(d)) != 0) { /* skip "." and ".." files, UUIDs never start with '.' */ if (dd->d_name[0] == '.') continue; - ret = fstatat(dirfd(d), dd->d_name, &st, 0); + ret = fstatat(dir_fd, dd->d_name, &st, 0); if (ret != 0) { log_tag("uuid:by-uuid:%u:%u: fstatat(%s) failed, %s\n", major(device), minor(device), dd->d_name, strerror(errno)); /* generic error, ignore and continue the search */