From: Danny Al-Gaaf Date: Fri, 10 May 2013 17:11:26 +0000 (+0200) Subject: ceph-monstore-tool.cc: check if open() was successful X-Git-Tag: v0.63~41^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c006151c05b0599c3459ce051451ea0ad1b8dbdf;p=ceph.git ceph-monstore-tool.cc: check if open() was successful 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 --- diff --git a/src/tools/ceph-monstore-tool.cc b/src/tools/ceph-monstore-tool.cc index c62e16721f40..7e1ca6bc5b5b 100644 --- a/src/tools/ceph-monstore-tool.cc +++ b/src/tools/ceph-monstore-tool.cc @@ -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; }