[PATCH] Improve pid2tcb to handle abnormal input on linux

Wang Chao wang.chao at cn.fujitsu.com
Wed Sep 15 00:55:29 UTC 2010


If we call pid2tcb with 0 as argument, the function will
return the first tcp with flag TCB_INUSE, which will cause
problems if we call wait with pgrp id 0 on linux.

* strace.c (pid2tcb): Return NULL if argument is process
  group id on linux.
---
 strace.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/strace.c b/strace.c
index 3cb3758..77ae7e9 100644
--- a/strace.c
+++ b/strace.c
@@ -1343,6 +1343,11 @@ int pid;
 	int i;
 	struct tcb *tcp;
 
+#ifndef USE_PROCFS
+	if (pid == 0 || pid < -1)
+		return NULL;
+#endif
+
 	for (i = 0; i < tcbtabsize; i++) {
 		tcp = tcbtab[i];
 		if (pid && tcp->pid != pid)
-- 
1.6.5.2





More information about the Strace-devel mailing list