Skip to contentSkip to conversation

kbuild: fixdep: Check fstat(2) return value

PATCH In review Tom Rini 2 participants 4 messages Dec 7, 2015 – Feb 17, 2016 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 kbuild: fixdep: Check fstat(2) return value

Coverity has recently added a check that will find when we don't check the return code from fstat(2). Copy/paste the checking logic that print_deps() has with an appropriate re-wording of the perror() message.

---
Note that I don't have a CID here was I found this in U-Boot and the kernel hasn't yet done a build with this test being enabled.

---
 scripts/basic/fixdep.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/basic/fixdep.c +5 -1
index c68fd61..e3d9678 100644
@@ -274,7 +274,11 @@ static void do_config_file(const char *filename)
 		perror(filename);
 		exit(2);
 	}
-	fstat(fd, &st);
+	if (fstat(fd, &st) < 0) {
+		fprintf(stderr, "fixdep: error fstat'ing config file: ");
+		perror(filename);
+		exit(2);
+	}
 	if (st.st_size == 0) {
 		close(fd);
 		return;
Signature · 1 line
1.7.9.5
author
#1 lore raw
Quoted 23 lines · Tom Rini

Coverity has recently added a check that will find when we don't check the return code from fstat(2). Copy/paste the checking logic that print_deps() has with an appropriate re-wording of the perror() message.

---
Note that I don't have a CID here was I found this in U-Boot and the kernel hasn't yet done a build with this test being enabled.

---
 scripts/basic/fixdep.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/basic/fixdep.c +0 -0
index c68fd61..e3d9678 100644
@@ -274,7 +274,11 @@ static void do_config_file(const char *filename)
                perror(filename);
                exit(2);

scripts/basic/fixdep.c static void do_config_file(const char *filename) · line 284

Quoted 10 lines
scripts/basic/fixdep.c +5 -1
        }
-       fstat(fd, &st);
+       if (fstat(fd, &st) < 0) {
+               fprintf(stderr, "fixdep: error fstat'ing config file: ");
+               perror(filename);
+               exit(2);
+       }
        if (st.st_size == 0) {
                close(fd);
                return;

Adding stable@ since this applies to 4.4. Any comments? Thanks!

Signature · 1 line
Tom

A message that is not in the archive (sent off-list or not yet received): CA+M6bXnTB286iFoSFUneGq=1PCJtmnR_PBrqMeM4eu-Aj1BqMA@mail.gmail.com

author
#3 lore raw
Quoted 30 lines · Tom Rini
Quoted 28 lines · Tom Rini

Coverity has recently added a check that will find when we don't check the return code from fstat(2). Copy/paste the checking logic that print_deps() has with an appropriate re-wording of the perror() message.

---
Note that I don't have a CID here was I found this in U-Boot and the kernel hasn't yet done a build with this test being enabled.

---
 scripts/basic/fixdep.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/basic/fixdep.c +3 -1
index c68fd61..e3d9678 100644
@@ -274,7 +274,11 @@ static void do_config_file(const char *filename)
                perror(filename);
                exit(2);
        }
-       fstat(fd, &st);
+       if (fstat(fd, &st) < 0) {
+               fprintf(stderr, "fixdep: error fstat'ing config file: ");
+               perror(filename);
Quoted 8 lines

scripts/basic/fixdep.c static void do_config_file(const char *filename) · line 284

Quoted 5 lines
scripts/basic/fixdep.c +2 -0
+               exit(2);
+       }
        if (st.st_size == 0) {
                close(fd);
                return;

Adding stable@ since this applies to 4.4. Any comments? Thanks!

Ping? Thanks!

Signature · 1 line
Tom
#4 lore raw
Quoted 1 line · Tom Rini

Ping? Thanks!

Applied now, thanks.

Michal