Skip to content

Commit d112118

Browse files
committed
get_exec_info: error out if we run out of space rewriting pathname
Since proc_read_link() is destructive on error we could end up with missing NUL terminator in the rewritten pathname. Coverity CID 560390.
1 parent ec12f0f commit d112118

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/exec_ptrace.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,8 +1120,13 @@ get_exec_info(pid_t pid, bool is_execveat, struct sudo_ptrace_regs *regs,
11201120
if (errstr == NULL) {
11211121
/* Rewrite argbuf with link target (if it is one). */
11221122
ssize_t len = proc_read_link(pid, name, argbuf, bufsize);
1123-
if (len != -1)
1124-
nread = len + 1;
1123+
if (len == -1) {
1124+
sudo_debug_printf(
1125+
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
1126+
"unable to rewrite pathname for process %d", (int)pid);
1127+
goto bad;
1128+
}
1129+
nread = len + 1;
11251130
}
11261131
}
11271132

0 commit comments

Comments
 (0)