lkml.org 
[lkml]   [2016]   [Oct]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH 06/10] scripts/basic/fixdep: Complete error handling in do_config_file()
From
Date
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 27 Oct 2016 22:02:42 +0200

Return values were not checked from four calls of the function "close".

This issue was detected also by using the Coccinelle software.


Add a bit of exception handling there.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
scripts/basic/fixdep.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index 5f6a4f4..be0fdaa 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -284,27 +284,33 @@ static void do_config_file(const char *filename)
perror(filename);
exit(2);
}
- if (st.st_size == 0) {
- close(fd);
- return;
- }
+ if (st.st_size == 0)
+ goto close_fd;
map = malloc(st.st_size + 1);
if (!map) {
perror("fixdep: malloc");
- close(fd);
- return;
+ goto close_fd;
}
if (read(fd, map, st.st_size) != st.st_size) {
perror("fixdep: read");
- close(fd);
- return;
+ goto close_fd;
}
map[st.st_size] = '\0';
- close(fd);
-
+ if (close(fd))
+ goto close_failure;
parse_config_file(map);
-
free(map);
+ return;
+close_fd:
+ if (close(fd)) {
+close_failure:
+ {
+ int code = errno;
+
+ perror("fixdep: close");
+ exit(code);
+ }
+ }
}

/*
--
2.10.1
\
 
 \ /
  Last update: 2016-10-28 10:37    [W:0.158 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site