Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LNX.2.20.13.1707050044310.21060@monopod.intra.ispras.ru>
Date: Wed, 5 Jul 2017 00:51:05 +0300 (MSK)
From: Alexander Monakov <amonakov@...ras.ru>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] fix undefined behavior in ptrace

---
On Tue, 4 Jul 2017, Rich Felker wrote:
> Thoughts?

I'm not convinced it's a good idea, given that it's a Linux specific interface,
and the manpage rather explicitly discourages passing fewer than four
arguments.

Plus, handling SPARC-specific differences of argument counts for
PTRACE_{GET,SET}{FP,}REGS would be annoying.

What makes sense is to retrieve the fifth argument only when needed:

 src/linux/ptrace.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/linux/ptrace.c b/src/linux/ptrace.c
index 83b8022b..a3f393d9 100644
--- a/src/linux/ptrace.c
+++ b/src/linux/ptrace.c
@@ -7,14 +7,18 @@ long ptrace(int req, ...)
 {
 	va_list ap;
 	pid_t pid;
-	void *addr, *data, *addr2;
+	void *addr, *data, *addr2 = 0;
 	long ret, result;
 
 	va_start(ap, req);
 	pid = va_arg(ap, pid_t);
 	addr = va_arg(ap, void *);
 	data = va_arg(ap, void *);
-	addr2 = va_arg(ap, void *);
+	/* PTRACE_{READ,WRITE}{DATA,TEXT} (16...19) are specific to SPARC. */
+#ifdef PTRACE_READDATA
+	if ((unsigned)req - PTRACE_READDATA < 4)
+		addr2 = va_arg(ap, void *);
+#endif
 	va_end(ap);
 
 	if (req-1U < 3) data = &result;
-- 
2.11.0

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.