Skip to content

Commit fc8d67f

Browse files
AZero13millert
authored andcommitted
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).
1 parent 2f216a3 commit fc8d67f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/edit_open.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,10 @@ sudo_edit_openat_nofollow(int dfd, char *path, int oflags, mode_t mode)
300300
* Check if path is a symlink. This is racey but we detect whether
301301
* we lost the race in sudo_edit_is_symlink() after the open.
302302
*/
303-
if (lstat(path, &sb) == -1 && errno != ENOENT)
304-
goto done;
305-
if (S_ISLNK(sb.st_mode)) {
303+
if (lstat(path, &sb) == -1) {
304+
if (errno != ENOENT)
305+
goto done;
306+
} else if (S_ISLNK(sb.st_mode)) {
306307
errno = ELOOP;
307308
goto done;
308309
}

0 commit comments

Comments
 (0)