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

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

[PATCH sed] ck_fclose should unlink *before* calling do_ck_fclose.


From: NeilBrown
Subject: [PATCH sed] ck_fclose should unlink *before* calling do_ck_fclose.
Date: Tue, 3 Jun 2014 09:27:28 +1000

If do_ck_fclose gets an error from fclose() it will call
panic() which will try to close everything on the list.
As the file which fclose was called on is still on the list,
it will be fclose()ed again, which is undefined behaviour and
can result in a process crash.

So unlink from the list *before* calling do_ck_fclose().

If the error happens at fflush time instead of fclose time,
the fp will not end up being closed.  This is not a serious
problem, but it could be fixed by calling ck_fflush(cur->fp)
before unlinking, and do_ck_fclose(cur->fp) afterwards.


diff --git a/sed/utils.c b/sed/utils.c
index 0a5351105e32..0e451bc24c92 100644
--- a/sed/utils.c
+++ b/sed/utils.c
@@ -297,8 +297,8 @@ ck_fclose(stream)
     {
       if (!stream || stream == cur->fp)
        {
-         do_ck_fclose (cur->fp);
          prev->link = cur->link;
+         do_ck_fclose (cur->fp);
          free(cur->name);
          free(cur);
        }

Attachment: signature.asc
Description: PGP signature


reply via email to

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