fix undefined behavior in ptrace
authorAlexander Monakov <amonakov@ispras.ru>
Tue, 4 Jul 2017 21:51:05 +0000 (00:51 +0300)
committerRich Felker <dalias@aerifal.cx>
Tue, 4 Jul 2017 21:53:58 +0000 (17:53 -0400)
src/linux/ptrace.c

index 83b8022beefa8afc9abeb19dfc7e9bac35d605e8..a3f393d956b3c73c63ec7f7636f315e76be54645 100644 (file)
@@ -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;