bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: gawk segfaults on opening non-existent file


From: Aharon Robbins
Subject: Re: gawk segfaults on opening non-existent file
Date: Fri, 20 Jan 2006 13:52:20 +0200

Greetings. Re this:

> Date: Tue, 17 Jan 2006 23:09:50 +0100
> From: Rafael Garcia-Suarez <address@hidden>
> Subject: gawk segfaults on opening non-existent file
> To: address@hidden
>
> Apologies if this was reported before, but I didn't find any archives.
>
> It appears that gawk 3.1.5 segfaults if it tries to open a file that
> does not exist. See the bug report at :
> http://qa.mandriva.com/show_bug.cgi?id=20050
> (but this is reproducible very simply).
>
> I have written a patch to fix this : basically, avoid freeing a
> pointer that will continue to be used afterwards.
> Please find the patch in the CVS at :
> http://cvs.mandriva.com/cgi-bin/cvsweb.cgi/~checkout~/SPECS/gawk/gawk-3.1.5-open.patch?rev=1.1&content-type=text/plain

Thanks for the bug report. It's a known problem. The official patch
is below.

Thanks,

Arnold
----------------
Fri Aug 12 13:10:33 2005  Arnold D. Robbins  <address@hidden>

        * io.c (iop_alloc): Only free `iop' if it was malloc'ed in
        the first place.

--- ../gawk-3.1.5/io.c  2005-07-26 21:07:43.000000000 +0300
+++ io.c        2005-08-12 13:10:28.000000000 +0300
@@ -2480,9 +2480,12 @@
 {
        struct stat sbuf;
        struct open_hook *oh;
+       int iop_malloced = FALSE;
 
-       if (iop == NULL)
+       if (iop == NULL) {
                emalloc(iop, IOBUF *, sizeof(IOBUF), "iop_alloc");
+               iop_malloced = TRUE;
+       }
        memset(iop, '\0', sizeof(IOBUF));
        iop->flag = 0;
        iop->fd = fd;
@@ -2495,7 +2498,8 @@
        }
 
        if (iop->fd == INVALID_HANDLE) {
-               free(iop);
+               if (iop_malloced)
+                       free(iop);
                return NULL;
        }
        if (isatty(iop->fd))




reply via email to

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