From 1547a7fc420a5049e50e1036abe0daf85a8304aa Mon Sep 17 00:00:00 2001 From: AZero13 Date: Tue, 16 Dec 2025 22:17:39 -0500 Subject: [PATCH] Do not work on sb if it is unitialized. lstat(path, &sb) == -1 can happen, leaving sb uninitialized. When this happens, we do not want to run S_ISLNK(sb.st_mode). --- src/edit_open.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/edit_open.c b/src/edit_open.c index 6bb76538d4..2d508990a3 100644 --- a/src/edit_open.c +++ b/src/edit_open.c @@ -300,9 +300,10 @@ sudo_edit_openat_nofollow(int dfd, char *path, int oflags, mode_t mode) * Check if path is a symlink. This is racey but we detect whether * we lost the race in sudo_edit_is_symlink() after the open. */ - if (lstat(path, &sb) == -1 && errno != ENOENT) - goto done; - if (S_ISLNK(sb.st_mode)) { + if (lstat(path, &sb) == -1) { + if (errno != ENOENT) + goto done; + } else if (S_ISLNK(sb.st_mode)) { errno = ELOOP; goto done; }