From 6cd461d9f89cca12df5f7311afc182bc432b036c Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 10 May 2022 11:23:44 -0600 Subject: [PATCH] ptrace_write_string: make sure we always write the terminating NUL. We can't check *str for NUL since it may not have been written yet. --- src/exec_ptrace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/exec_ptrace.c b/src/exec_ptrace.c index c648680c7..b2bda375b 100644 --- a/src/exec_ptrace.c +++ b/src/exec_ptrace.c @@ -465,8 +465,10 @@ ptrace_write_string(pid_t pid, long addr, const char *str) __func__, (int)pid, addr, (int)sizeof(u.buf), u.buf); debug_return_size_t(-1); } - if (*str == '\0') + if ((u.word & 0xff) == 0) { + /* If the last byte we wrote is a NUL we are done. */ debug_return_size_t(str - str0 + 1); + } addr += sizeof(long); } }