diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2017-12-30 09:32:12 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-12-30 09:32:12 -0800 |
commit | 1e20bc9c73df0f45f7a4d8dd8fbb9af18931c26f (patch) | |
tree | e828a896de48677ed5b50f5993a69808588e7fd5 | |
parent | bc6ec7cccbe01039bb6418f8c8c09b24ed5b9ef3 (diff) | |
download | subsurface-1e20bc9c73df0f45f7a4d8dd8fbb9af18931c26f.tar.gz |
Cleanup: consistently handle file open failures
In part based on
Coverity CID 45129
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | core/uemis-downloader.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/core/uemis-downloader.c b/core/uemis-downloader.c index 4ab165406..87e9e934c 100644 --- a/core/uemis-downloader.c +++ b/core/uemis-downloader.c @@ -479,7 +479,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in, int timeout = UEMIS_LONG_TIMEOUT; reqtxt_file = subsurface_open(reqtxt_path, O_RDWR | O_CREAT, 0666); - if (reqtxt_file == -1) { + if (reqtxt_file < 0) { *error_text = "can't open req.txt"; #ifdef UEMIS_DEBUG fprintf(debugfile, "open %s failed with errno %d\n", reqtxt_path, errno); @@ -529,6 +529,13 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in, snprintf(fl, 13, "ANS%d.TXT", filenr - 1); ans_path = build_filename(build_filename(path, "ANS"), fl); ans_file = subsurface_open(ans_path, O_RDONLY, 0666); + if (ans_file < 0) { + *error_text = "can't open Uemis response file"; +#ifdef UEMIS_DEBUG + fprintf(debugfile, "open %s failed with errno %d\n", ans_path, errno); +#endif + return false; + } read(ans_file, tmp, 100); close(ans_file); #if UEMIS_DEBUG & 8 @@ -558,7 +565,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in, assembling_mbuf = false; } reqtxt_file = subsurface_open(reqtxt_path, O_RDWR | O_CREAT, 0666); - if (reqtxt_file == -1) { + if (reqtxt_file < 0) { *error_text = "can't open req.txt"; fprintf(stderr, "open %s failed with errno %d\n", reqtxt_path, errno); return false; @@ -573,7 +580,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in, searching = false; } reqtxt_file = subsurface_open(reqtxt_path, O_RDWR | O_CREAT, 0666); - if (reqtxt_file == -1) { + if (reqtxt_file < 0) { *error_text = "can't open req.txt"; fprintf(stderr, "open %s failed with errno %d\n", reqtxt_path, errno); return false; @@ -588,6 +595,13 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in, ans_path = build_filename(intermediate, fl); free(intermediate); ans_file = subsurface_open(ans_path, O_RDONLY, 0666); + if (ans_file < 0) { + *error_text = "can't open Uemis response file"; +#ifdef UEMIS_DEBUG + fprintf(debugfile, "open %s failed with errno %d\n", ans_path, errno); +#endif + return false; + } free(ans_path); size = bytes_available(ans_file); if (size > 3) { @@ -621,6 +635,14 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in, ans_path = build_filename(intermediate, fl); free(intermediate); ans_file = subsurface_open(ans_path, O_RDONLY, 0666); + if (ans_file < 0) { + *error_text = "can't open Uemis response file"; +#ifdef UEMIS_DEBUG + fprintf(debugfile, "open %s failed with errno %d\n", ans_path, errno); +#endif + return false; + } + free(ans_path); size = bytes_available(ans_file); if (size > 3) { |