bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] freopen SEGFAULT on win32 with filename == NULL


From: Bruno Haible
Subject: Re: [PATCH] freopen SEGFAULT on win32 with filename == NULL
Date: Wed, 31 Aug 2011 10:15:31 +0200
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

Claudio Bley wrote:
> When calling 
> 
> freopen(NULL, mode, stream);
> 
> on MS Windows using MinGW segfaults because it tries to strcmp(NULL,
> "/dev/null")... *ouch*
> 
> --------------------
> --- freopen.c.orig    2011-08-03 14:22:15 +0200
> +++ freopen.c 2011-08-25 21:01:46 +0200
> @@ -38,7 +38,7 @@
>  rpl_freopen (const char *filename, const char *mode, FILE *stream)
>  {
>  #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
> -  if (strcmp (filename, "/dev/null") == 0)
> +  if (filename && strcmp (filename, "/dev/null") == 0)
>      filename = "NUL";
>  #endif
>  
> --------------------

Yes, thanks for the fix. I'm applying this is your name. (The "tiny change"
mark means that the change does not warrant the exchange of a copyright
assignment.)



2011-08-31  Claudio Bley  <address@hidden>  (tiny change)

        freopen: Don't crash if the filename argument is NULL.
        * lib/freopen.c (rpl_freopen): Don't compare the filename if it is
        NULL.

--- lib/freopen.c.orig  Wed Aug 31 09:47:57 2011
+++ lib/freopen.c       Wed Aug 31 09:47:25 2011
@@ -41,7 +41,7 @@
 rpl_freopen (const char *filename, const char *mode, FILE *stream)
 {
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-  if (strcmp (filename, "/dev/null") == 0)
+  if (filename != NULL && strcmp (filename, "/dev/null") == 0)
     filename = "NUL";
 #endif
 

-- 
In memoriam Magomed Yevloyev <http://en.wikipedia.org/wiki/Magomed_Yevloyev>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]