[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#340531: libc6: freopen() function closes unrelated streams.



Package: libc6
Version: 2.3.5-6
Severity: normal


While exploring lynx cgi support with this html page:

	<CENTER><A HREF="lynxcgi:/usr/local/bin/vile">test me</A></CENTER>

I found that vile dumped core (my problem to debug).  However,
I found that libc6 also had a bug.  The relevant chunk of code
in vile looks like this (TRACE is a compile-time macro which writes
to a trace file):

	TRACE(("call freopen(%s) for stdin\n", tty));
	if ((freopen(tty, "r", stdin)) == 0
	    || !isatty(fileno(stdin))) {
	    TRACE(("...failed to reopen stdin\n"));
	    fprintf(stderr, "cannot open a terminal (%s)\n", tty);
	    tidy_exit(BADEXIT);
	}
	TRACE(("...successfully reopened stdin\n"));

The call to freopen() is causing the stream for TRACE's output to
close, so the last line in the output is the first TRACE shown in
this chunk.  Putting an abort() before the last TRACE proves that
the code is getting that far.

Normally this chunk of code is run when redirecting stdout
to vile, e.g.,

	ls | vile

and in that case I see no problem with the stream.  For this special
case, lynx has setup the subprocess's stdin/stdout so they are via
a pipe, and neither is a tty (and there is no data on stdin).

valgrind doesn't report anything odd.  Moving this chunk to the
beginning of the program (setting tty to "/dev/tty") has the same
effect, so it is unlikely that there are other causes.

For reference, this is vile 9.5c

-- System Information:
Debian Release: testing/unstable
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.4.27-td2
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)

-- no debconf information



Reply to: