--- Denis Vlasenko <[EMAIL PROTECTED]> wrote:

> Applied with some other minor changes added, please check svn
> and yell if you see something bad.
> 
> vda
> 

Yelling! I found several problems, the attached patch fixes them.

1. pid_is_exec(): you changed the return to (~n) from something akin to (!n). 
This works
fine if n==0, but then n!=0, the returned value is also non-zero, and it breaks 
the
calling code.
2. When vfork()ing, the parent should exit(0) and not return(0), since the 
child has run
quite some time and may have changed the return address in stack. So, no 
returns in the
parent, only function calls. Added a comment about that. Better safe than sorry.
3. After vfork(), the check of (pid==0) to see if I'm the parent is wrong. It 
should be
(pid!=0).
4. Added a setsid() call just before daemonize_or_rexec.

Alex


      
____________________________________________________________________________________
Luggage? GPS? Comic books? 
Check out fitting gifts for grads at Yahoo! Search
http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz
Index: debianutils/start_stop_daemon.c
===================================================================
--- debianutils/start_stop_daemon.c	(revision 19395)
+++ debianutils/start_stop_daemon.c	(working copy)
@@ -46,7 +46,7 @@
 	n = strcmp(execbuf, name);
 	if (ENABLE_FEATURE_CLEAN_UP)
 		free(execbuf);
-	return ~n; /* nonzero (true) if execbuf == name */
+	return !n; /* nonzero (true) if execbuf == name */
 }
 
 static int pid_is_user(int pid, int uid)
@@ -301,12 +301,12 @@
 		pid_t pid = vfork();
 		if (pid < 0) /* error */
 			bb_perror_msg_and_die("vfork");
-		if (pid == 0) /* parent */
-			return 0;
-		}
+		if (pid != 0) /* parent */
+			exit(0); /* the child may have changed the stack, so no return possible, only function calls */
 		/* child */
 		/* Redirect stdio to /dev/null, close extra FDs.
 		 * We do not actually daemonize because of DAEMON_ONLY_SANITIZE */
+		setsid();
 		bb_daemonize_or_rexec(
 			DAEMON_DEVNULL_STDIO
 			+ DAEMON_CLOSE_EXTRA_FDS
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to