bug-patch
[Top][All Lists]
Advanced

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

Re: [bug-patch] [PATCH] avoid using stat.st_dev and st_ino members of un


From: Andreas Gruenbacher
Subject: Re: [bug-patch] [PATCH] avoid using stat.st_dev and st_ino members of uninitialized "outst"
Date: Mon, 14 Feb 2011 12:50:46 +0100
User-agent: KMail/1.12.4 (Linux/2.6.36-rc7+; KDE/4.3.5; i686; ; )

Hi Jim,

On Monday 07 February 2011 19:17:02 Jim Meyering wrote:
> Testing my recent changes, I found an unrelated used-uninitialized bug.
> It did not look easy to abuse, since the affected data are used only in
> determining whether a file has already been processed.

I see how this can trigger for ed-style diffs because outst is not used.
That can easily be fixed though (plus safety check):


diff --git a/src/patch.c b/src/patch.c
index 77be499..0cdaeb9 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -105,6 +105,7 @@ main (int argc, char **argv)
     mode_t file_type;
     int outfd = -1;
 
+    outst.st_size = -1;
     exit_failure = 2;
     program_name = argv[0];
     init_time ();
@@ -248,10 +249,9 @@ main (int argc, char **argv)
                      outstate.ofp);
        if (! dry_run && ! outfile && ! skip_rest_of_patch)
          {
-           struct stat statbuf;
-           if (fstat (outfd, &statbuf) != 0)
+           if (fstat (outfd, &outst) != 0)
              pfatal ("%s", TMPOUTNAME);
-           outstate.zero_output = statbuf.st_size == 0;
+           outstate.zero_output = outst.st_size == 0;
          }
        close (outfd);
        outfd = -1;
@@ -500,6 +500,7 @@ main (int argc, char **argv)
                        set_file_attributes (TMPOUTNAME, attr, inname, &instat,
                                             mode, &new_time);
 
+                     assert (outst.st_size != -1);
                      move_file (TMPOUTNAME, &TMPOUTNAME_needs_removal, &outst,
                                 outname, mode, backup);
 

Do you see a way how the assert could still trigger?

Thanks,
Andreas



reply via email to

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