]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-monstore-tool.cc: check if open() was successful
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Fri, 10 May 2013 17:11:26 +0000 (19:11 +0200)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Fri, 10 May 2013 22:02:56 +0000 (00:02 +0200)
Should fix: "fd" is passed to a parameter that cannot be negative.

CID 1019566 Improper use of negative value (NEGATIVE_RETURNS, CWE-394)

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
src/tools/ceph-monstore-tool.cc

index c62e16721f40f846196181f2a0b2d3f89f5f7c6f..7e1ca6bc5b5b3a72c0083f26a61ff34219576c24 100644 (file)
@@ -177,7 +177,11 @@ int main(int argc, char **argv) {
 
   int fd;
   if (vm.count("out")) {
-    fd = open(out_path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666);
+    if ((fd = open(out_path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
+      int _err = errno;
+      std::cerr << "Couldn't open " << out_path << cpp_strerror(_err) << std::endl; 
+      return 1;
+    }
   } else {
     fd = STDOUT_FILENO;
   }