VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   55 Tags
author: Jesper Juhl <jj@chaosbits.net> 2010-12-24 21:28:56 +0100 committer: Michal Marek <mmarek@suse.cz> 2010-12-29 15:06:54 +0100 commit: 96aebafa63418f447ddc823e40da341cc40553dd parent: 731ece41fb1047816303295a0cdfed90a528137e
Commit Summary:
gen_init_cpio: Avoid race between call to stat() and call to open()
Diffstat:
1 file changed, 6 insertions, 6 deletions
diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index 59df70d9d1dc..f463cafdccb2 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -309,18 +309,18 @@ static int cpio_mkfile(const char *name, const char *location,
 
 	mode |= S_IFREG;
 
-	retval = stat (location, &buf);
-	if (retval) {
-		fprintf (stderr, "File %s could not be located\n", location);
-		goto error;
-	}
-
 	file = open (location, O_RDONLY);
 	if (file < 0) {
 		fprintf (stderr, "File %s could not be opened for reading\n", location);
 		goto error;
 	}
 
+	retval = fstat (file, &buf);
+	if (retval) {
+		fprintf (stderr, "File %s could not be stat()'ed\n", location);
+		goto error;
+	}
+
 	filebuf = malloc(buf.st_size);
 	if (!filebuf) {
 		fprintf (stderr, "out of memory\n");