Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 24 Oct 2012 16:59:05 -0400
From: Rich Felker <>
Subject: Re: Possible file stream bug

On Wed, Oct 24, 2012 at 09:36:28PM +0200, Paul Schutte wrote:
> Hi
> I compiled and linked libwebserver-0.5.3 against musl.
> It would just strangely break halfway through a request. After hours of
> searching, I found the problem.
> I can demonstrate it with the following code:
> #include <unistd.h>
> #include <stdio.h>
> int main() {
>     FILE *fstream;
>     fclose(stdout);
>     fstream=freopen("/dev/tty","w",stdout);
>     if (fstream==NULL) {
>         fprintf(stderr,"freopen failed\n");
>     }
>     printf("test this\n");
>     return 0;
> }
> This snippet works fine when using glibc.

This code is invalid; you have invoked undefined behavior by accessing
stdout (passing it to freopen) after it was closed with fclose. Remove
the fclose and it works correctly. This code would certainly cause
memory corruption and/or crash if it were used on any FILE other than
one of the 3 builtin ones (since the memory would have been returned
to the heap when fclose was called) so there is no sense in trying to
support this invalid usage. You should file a bug report with the


Powered by blists - more mailing lists

Your e-mail address:

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.