From bc45cded3f4dc3855358126c64cc94f2a1f249c5 Mon Sep 17 00:00:00 2001 From: Sam Lang Date: Tue, 25 Sep 2012 07:03:57 -0700 Subject: [PATCH] cephfs: Fixes for coverity bugs 716840 and 716970 Fixes for two coverity bugs in cephfs.cc. 716840 (CHECKED_RETURN) reported that the return value from fstat wasn't getting checked. It now is checked, reports an error and returns to the caller. 716970 (NEGATIVE_RETURNS) reported that the file descriptor passed to fstat (*fd) might be negative, which isn't allowed. The check at the top that open failed wasn't aborting the function (when *fd < 0), now it does. Signed-off-by: Sam Lang --- src/cephfs.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cephfs.cc b/src/cephfs.cc index b0bf18cf32a6f..d763c53894686 100644 --- a/src/cephfs.cc +++ b/src/cephfs.cc @@ -194,6 +194,7 @@ int init_options(int argc, char **argv, int *fd, char **path, int *cmd, *fd = open(argv[1], O_RDONLY); if (*fd < 0) { cerr << "error opening path: " << strerror(*fd) << endl; + return 1; } if (!strcmp(argv[2], "show_layout")) { @@ -275,7 +276,13 @@ int init_options(int argc, char **argv, int *fd, char **path, int *cmd, i += 2; } - fstat (*fd, &stat_field); + int r = fstat (*fd, &stat_field); + if (r < 0) { + int err = errno; + cerr << "error doing stat file: " << cpp_strerror(errno) << endl; + return 1; + } + if (S_ISREG(stat_field.st_mode)) { // open read-write to set layout close(*fd); *fd = open(argv[1], O_RDWR); -- 2.39.5