[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-patch] [PATCH] avoid using stat.st_dev and st_ino members of uninit
From: |
Jim Meyering |
Subject: |
[bug-patch] [PATCH] avoid using stat.st_dev and st_ino members of uninitialized "outst" |
Date: |
Mon, 07 Feb 2011 19:17:02 +0100 |
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.
This fixes it:
I've deliberately left out the ChangeLog patch,
since they usually cause more trouble than they're worth.
(which is why I generate the ChangeLog from commit logs in
coreutils and other packages)
2011-02-07 Jim Meyering <address@hidden>
avoid using stat.st_dev and st_ino members of uninitialized "outst"
This local variable is used in move_file, and *may* be initialized
by the preceding call to spew_output. However, when that call is
skipped, move_file uses those members uninitialized.
* src/patch.c (main): Initialize the st_size member to -1 to act
as a witness. Then, we can test whether an explicit stat/fstat is
required just prior to calling move_file.
>From c24017d37d71ded8fc3466c8330014d92bbd59b7 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 7 Feb 2011 19:07:34 +0100
Subject: [PATCH] avoid using stat.st_dev and st_ino members of uninitialized
"outst"
This local variable is used in move_file, and *may* be initialized
by the preceding call to spew_output. However, when that call is
skipped, move_file uses those members uninitialized.
* src/patch.c (main): Initialize the st_size member to -1 to act
as a witness. Then, we can test whether an explicit stat/fstat is
required just prior to calling move_file.
---
src/patch.c | 11 +++++++++++
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/src/patch.c b/src/patch.c
index 77be499..21740c9 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 ();
@@ -500,6 +501,16 @@ main (int argc, char **argv)
set_file_attributes (TMPOUTNAME, attr, inname, &instat,
mode, &new_time);
+ /* We may have useful data in outst, via spew_output.
+ If not, get it now, via the file descriptor when
+ possible. */
+ if (outst.st_size == -1)
+ {
+ if (0 <= outfd
+ ? fstat (outfd, &outst)
+ : stat (TMPOUTNAME, &outst))
+ fatal ("failed to stat %s", quotearg (TMPOUTNAME));
+ }
move_file (TMPOUTNAME, &TMPOUTNAME_needs_removal, &outst,
outname, mode, backup);
--
1.7.4.2.g597a6
- [bug-patch] [PATCH] avoid using stat.st_dev and st_ino members of uninitialized "outst",
Jim Meyering <=