[PATCH] sanitize when kernel starts init without any fd opened

Maxime Bizon mbizon at freebox.fr
Tue Jun 12 08:29:49 UTC 2007


On Mon, 2007-06-11 at 22:29 -0400, Mike Frysinger wrote:

> > So you mean any code using libc daemon(3) is broken ?
> 
> how is that function relevant to the discussion ?  it can be safely used 
> regardless of the state of stdin/stdout/stderr before it is called

main()
{
	fd = socket(...);
	fd2 = pipe(...);
	[...]

	/* ok all set */
	daemon(0, 0)

	[...]
	FD_SET(fd, &rfd);
	select(...);
	[...]
}

It's a valid and common daemon(3) usage scheme to me, but this code will
break if fd and fd2 get fd between 0 and 2.

-- 
Maxime




More information about the busybox mailing list