Browse Source

trace: Use properly sized type for PTRACE_GETEVENTMSG

Without this, on 64-bit systems, ptrace call corrupts memory because
it stores 64bit value to 32bit pid_t variable.

Signed-off-by: Michal Sojka <michal.sojka@cvut.cz>
Michal Sojka 5 years ago
parent
commit
5f57223913
1 changed files with 3 additions and 1 deletions
  1. 3 1
      trace/trace.c

+ 3 - 1
trace/trace.c

@@ -211,7 +211,9 @@ static void tracer_cb(struct uloop_process *c, int ret)
 			   (ret >> 8) == (SIGTRAP | (PTRACE_EVENT_CLONE << 8))) {
 			struct tracee *child = calloc(1, sizeof(struct tracee));
 
-			ptrace(PTRACE_GETEVENTMSG, c->pid, 0, &child->proc.pid);
+			unsigned long msg;
+			ptrace(PTRACE_GETEVENTMSG, c->pid, 0, &msg);
+			child->proc.pid = msg;
 			child->proc.cb = tracer_cb;
 			ptrace(ptrace_restart, child->proc.pid, 0, 0);
 			uloop_process_add(&child->proc);