summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Monakov <amonakov@ispras.ru>2017-07-05 00:51:05 +0300
committerRich Felker <dalias@aerifal.cx>2017-07-04 17:53:58 -0400
commitbc42dcbfd9466c22d8ab0f8235e5091689a95aad (patch)
tree0d33a79c5b386f7358b7ec250d3f50a1b028efad
parentd906fa3118c888227d858b6d642a09e055eca2b4 (diff)
downloadmusl-bc42dcbfd9466c22d8ab0f8235e5091689a95aad.tar.gz
fix undefined behavior in ptrace
-rw-r--r--src/linux/ptrace.c8
1 files 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;