|
1 | 1 | /* |
2 | 2 | * SPDX-License-Identifier: ISC |
3 | 3 | * |
4 | | - * Copyright (c) 2009-2020 Todd C. Miller <Todd.Miller@sudo.ws> |
| 4 | + * Copyright (c) 2009-2023, 2025-2026 Todd C. Miller <Todd.Miller@sudo.ws> |
5 | 5 | * |
6 | 6 | * Permission to use, copy, modify, and distribute this software for any |
7 | 7 | * purpose with or without fee is hereby granted, provided that the above |
@@ -49,14 +49,14 @@ iolog_parse_loginfo(int dfd, const char *iolog_dir) |
49 | 49 | debug_decl(iolog_parse_loginfo, SUDO_DEBUG_UTIL); |
50 | 50 |
|
51 | 51 | if (dfd == -1) { |
52 | | - if ((tmpfd = open(iolog_dir, O_RDONLY|O_DIRECTORY)) == -1) { |
| 52 | + if ((tmpfd = open(iolog_dir, O_RDONLY|O_DIRECTORY|O_NOFOLLOW)) == -1) { |
53 | 53 | sudo_warn("%s", iolog_dir); |
54 | 54 | goto bad; |
55 | 55 | } |
56 | 56 | dfd = tmpfd; |
57 | 57 | } |
58 | | - if ((fd = openat(dfd, "log.json", O_RDONLY, 0)) == -1) { |
59 | | - fd = openat(dfd, "log", O_RDONLY, 0); |
| 58 | + if ((fd = openat(dfd, "log.json", O_RDONLY|O_NOFOLLOW, 0)) == -1) { |
| 59 | + fd = openat(dfd, "log", O_RDONLY|O_NOFOLLOW, 0); |
60 | 60 | legacy = true; |
61 | 61 | } |
62 | 62 | if (tmpfd != -1) |
@@ -103,7 +103,7 @@ iolog_write_info_file_legacy(int dfd, struct eventlog *evlog) |
103 | 103 | int error, fd; |
104 | 104 | debug_decl(iolog_info_write_log, SUDO_DEBUG_UTIL); |
105 | 105 |
|
106 | | - fd = iolog_openat(dfd, "log", O_CREAT|O_TRUNC|O_WRONLY); |
| 106 | + fd = iolog_openat(dfd, "log", O_CREAT|O_TRUNC|O_WRONLY|O_NOFOLLOW); |
107 | 107 | if (fd == -1 || (fp = fdopen(fd, "w")) == NULL) { |
108 | 108 | sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO, |
109 | 109 | "unable to %sopen %s/log", fd == -1 ? "" : "fd", evlog->iolog_path); |
@@ -178,7 +178,7 @@ iolog_write_info_file_json(int dfd, struct eventlog *evlog) |
178 | 178 | if (!eventlog_store_json(&jsonc, evlog)) |
179 | 179 | goto done; |
180 | 180 |
|
181 | | - fd = iolog_openat(dfd, "log.json", O_CREAT|O_TRUNC|O_WRONLY); |
| 181 | + fd = iolog_openat(dfd, "log.json", O_CREAT|O_TRUNC|O_WRONLY|O_NOFOLLOW); |
182 | 182 | if (fd == -1 || (fp = fdopen(fd, "w")) == NULL) { |
183 | 183 | sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO, |
184 | 184 | "unable to %sopen %s/log.json", fd == -1 ? "" : "fd", |
|
0 commit comments