Page MenuHome GnuPG

file descriptor warning fixes for NetBSD when set*id
Closed, ResolvedPublic

Description

When exec'ing child processes (netstat and vmstat), make sure the standard
file descriptors (0, 1, 2) are open. This avoids multiple warnings issued
under NetBSD about running set[ug]id programs with those descriptors closed.

The attached patch fixes this.

(This patch was written in 2004 by Julio Merino <jmmv@NetBSD.org> for pkgsrc. I
don't know why it was never reported upstream. See http://gnats.netbsd.org/26079
for more details.)

Details

Version
1.6.2

Event Timeline

Any reason why stdin and stdout are re-opened earlier than stderr?
I would use

  if (fstat (STDIN_FILENO, &statbuf) == -1 && errno ==EBADF)
    open ("/dev/null",O_RDONLY);
  if (fstat (STDOUT_FILENO, &statbuf) == -1 && errno ==EBADF)
    open ("/dev/null",O_RDONLY);
  if (fstat (STDERR_FILENO, &statbuf) == -1 && errno ==EBADF)
    open ("/dev/null",O_RDONLY);

right after the "Stuart code" line.

I've contacted jmmv and he wrote:
"This was a long time ago and I don't remember. The newly proposed patch sounds
good though."
So please go ahead with your version.

werner claimed this task.
werner removed a project: Restricted Project.