From 86380fc2c628df9df1dad8f96b8055394dff8950 Mon Sep 17 00:00:00 2001 From: wfjm Date: Sat, 27 Oct 2018 12:44:39 +0200 Subject: [PATCH] coverity: catch exceptions in dtor --- doc/CHANGELOG.md | 1 + tools/src/librlink/RlinkConnect.cpp | 7 ++++--- tools/src/librlink/RlinkPortCuff.cpp | 8 +++++--- tools/src/librlink/RlinkServer.cpp | 8 +++++--- tools/src/librlinktpp/RtclAttnShuttle.cpp | 6 ++++-- tools/src/librw11/Rw11VirtEthTap.cpp | 14 +++++++++----- tools/src/librw11/Rw11VirtTermPty.cpp | 10 ++++++---- tools/src/librw11/Rw11VirtTermTcp.cpp | 14 +++++++++----- 8 files changed, 43 insertions(+), 25 deletions(-) diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 838077ad..e394e94e 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -66,6 +66,7 @@ The full set of tests is only run for tagged releases. - backend code review: - use for C++ compiles also `-Wpedantic` - fixes for uninitialized variables (coverity, all uncritical) + - catch exceptions in dtors (coverity, use Catch2Cerr) - now -Wunused-parameter clean (comment out unused params) - now -Wunused-variable clean (comment out so far unused code) - move `using namespace std` after includes (clang warning) diff --git a/tools/src/librlink/RlinkConnect.cpp b/tools/src/librlink/RlinkConnect.cpp index adfc219b..b7ebc911 100644 --- a/tools/src/librlink/RlinkConnect.cpp +++ b/tools/src/librlink/RlinkConnect.cpp @@ -1,6 +1,6 @@ -// $Id: RlinkConnect.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: RlinkConnect.cpp 1059 2018-10-27 10:34:16Z mueller $ // -// Copyright 2011-2017 by Walter F.J. Mueller +// Copyright 2011-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2018-10-27 1059 2.6.3 coverity fixup (uncaught exception in dtor) // 2017-04-22 883 2.6.2 add rbus monitor probe, add HasRbmon() // 2017-04-07 868 2.6.1 Dump(): add detail arg // 2017-02-20 854 2.6 use Rtime, drop TimeOfDayAsDouble @@ -163,7 +164,7 @@ RlinkConnect::RlinkConnect() RlinkConnect::~RlinkConnect() { - Close(); + Rtools::Catch2Cerr(__func__, [this](){ Close(); } ); } //------------------------------------------+----------------------------------- diff --git a/tools/src/librlink/RlinkPortCuff.cpp b/tools/src/librlink/RlinkPortCuff.cpp index c117e3a5..67dc2fba 100644 --- a/tools/src/librlink/RlinkPortCuff.cpp +++ b/tools/src/librlink/RlinkPortCuff.cpp @@ -1,6 +1,6 @@ -// $Id: RlinkPortCuff.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: RlinkPortCuff.cpp 1059 2018-10-27 10:34:16Z mueller $ // -// Copyright 2012-2017 by Walter F.J. Mueller +// Copyright 2012-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2018-10-27 1059 1.1.6 coverity fixup (uncaught exception in dtor) // 2017-04-15 875 1.1.5 Open(): set default scheme // 2017-03-04 858 1.1.4 use clock_gettime instead of gettimeofday // 2015-04-12 666 1.1.3 add noinit attribute @@ -86,7 +87,8 @@ RlinkPortCuff::RlinkPortCuff() RlinkPortCuff::~RlinkPortCuff() { - if (IsOpen()) RlinkPortCuff::Close(); + if (IsOpen()) Rtools::Catch2Cerr(__func__, + [this](){ RlinkPortCuff::Close(); } ); } //------------------------------------------+----------------------------------- diff --git a/tools/src/librlink/RlinkServer.cpp b/tools/src/librlink/RlinkServer.cpp index 1cbcb340..eb3cc1cb 100644 --- a/tools/src/librlink/RlinkServer.cpp +++ b/tools/src/librlink/RlinkServer.cpp @@ -1,6 +1,6 @@ -// $Id: RlinkServer.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: RlinkServer.cpp 1059 2018-10-27 10:34:16Z mueller $ // -// Copyright 2013-2017 by Walter F.J. Mueller +// Copyright 2013-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2018-10-27 1059 1.2.3 coverity fixup (uncaught exception in dtor) // 2017-04-07 868 1.2.2 Dump(): add detail arg // 2015-06-05 686 1.2.1 BUGFIX: CallAttnHandler(): fix race in hnext // 2015-04-04 662 1.2 BUGFIX: fix race in Stop(), use UnStop() @@ -40,6 +41,7 @@ #include "librtools/RosPrintBvi.hpp" #include "librtools/Rexception.hpp" #include "librtools/RlogMsg.hpp" +#include "librtools/Rtools.hpp" #include "RlinkServer.hpp" @@ -107,7 +109,7 @@ RlinkServer::RlinkServer() RlinkServer::~RlinkServer() { - Stop(); + Rtools::Catch2Cerr(__func__, [this](){ Stop(); } ); if (fspConn) fspConn->SetServer(0); } diff --git a/tools/src/librlinktpp/RtclAttnShuttle.cpp b/tools/src/librlinktpp/RtclAttnShuttle.cpp index 59b19546..abf466d3 100644 --- a/tools/src/librlinktpp/RtclAttnShuttle.cpp +++ b/tools/src/librlinktpp/RtclAttnShuttle.cpp @@ -1,4 +1,4 @@ -// $Id: RtclAttnShuttle.cpp 1049 2018-09-22 13:56:52Z mueller $ +// $Id: RtclAttnShuttle.cpp 1059 2018-10-27 10:34:16Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2018-10-27 1059 1.1.1 coverity fixup (uncaught exception in dtor) // 2014-12-30 625 1.1 adopt to Rlink V4 attn logic // 2014-11-08 602 1.0.3 cast int first to ptrdiff_t, than to ClientData // 2014-08-22 584 1.0.2 use nullptr @@ -31,6 +32,7 @@ #include "boost/bind.hpp" #include "librtools/Rexception.hpp" +#include "librtools/Rtools.hpp" #include "RtclAttnShuttle.hpp" @@ -69,7 +71,7 @@ RtclAttnShuttle::RtclAttnShuttle(uint16_t mask, Tcl_Obj* pobj) RtclAttnShuttle::~RtclAttnShuttle() { - Remove(); + Rtools::Catch2Cerr(__func__, [this](){ Remove();} ); ::close(fFdPipeWrite); ::close(fFdPipeRead); } diff --git a/tools/src/librw11/Rw11VirtEthTap.cpp b/tools/src/librw11/Rw11VirtEthTap.cpp index 48d3b2fd..6f9eb985 100644 --- a/tools/src/librw11/Rw11VirtEthTap.cpp +++ b/tools/src/librw11/Rw11VirtEthTap.cpp @@ -1,6 +1,6 @@ -// $Id: Rw11VirtEthTap.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: Rw11VirtEthTap.cpp 1059 2018-10-27 10:34:16Z mueller $ // -// Copyright 2014-2017 by Walter F.J. Mueller +// Copyright 2014-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -13,6 +13,8 @@ // // Revision History: // Date Rev Version Comment +// 2018-10-27 1059 1.0.1 coverity fixup (uncaught exception in dtor) +// coverity fixup (buffer not null terminated) // 2017-04-15 875 1.0 Initial version // 2014-06-09 561 0.1 First draft // --------------------------------------------------------------------------- @@ -36,6 +38,7 @@ #include "boost/bind.hpp" #include "librtools/RosFill.hpp" +#include "librtools/Rtools.hpp" #include "Rw11VirtEthTap.hpp" @@ -63,8 +66,9 @@ Rw11VirtEthTap::Rw11VirtEthTap(Rw11Unit* punit) Rw11VirtEthTap::~Rw11VirtEthTap() { if (fFd>=2) { - Server().RemovePollHandler(fFd); - close(fFd); + Rtools::Catch2Cerr(__func__, + [this](){ Server().RemovePollHandler(fFd); } ); + ::close(fFd); } } @@ -90,7 +94,7 @@ bool Rw11VirtEthTap::Open(const std::string& url, RerrMsg& emsg) struct ifreq ifr; ::memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, fUrl.Path().c_str(), IFNAMSIZ); + ::strncpy(ifr.ifr_name, fUrl.Path().c_str(), IFNAMSIZ-1); ifr.ifr_flags = IFF_TAP|IFF_NO_PI; if (::ioctl(fd, TUNSETIFF, &ifr) < 0) { diff --git a/tools/src/librw11/Rw11VirtTermPty.cpp b/tools/src/librw11/Rw11VirtTermPty.cpp index b88231f8..26e8e759 100644 --- a/tools/src/librw11/Rw11VirtTermPty.cpp +++ b/tools/src/librw11/Rw11VirtTermPty.cpp @@ -1,6 +1,6 @@ -// $Id: Rw11VirtTermPty.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: Rw11VirtTermPty.cpp 1059 2018-10-27 10:34:16Z mueller $ // -// Copyright 2013-2017 by Walter F.J. Mueller +// Copyright 2013-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2018-10-27 1059 1.0.3 coverity fixup (uncaught exception in dtor) // 2017-04-15 875 1.0.2 Open(): set default scheme // 2017-04-07 868 1.0.1 Dump(): add detail arg // 2013-03-06 495 1.0 Initial version @@ -59,8 +60,9 @@ Rw11VirtTermPty::Rw11VirtTermPty(Rw11Unit* punit) Rw11VirtTermPty::~Rw11VirtTermPty() { if (fFd>=2) { - Server().RemovePollHandler(fFd); - close(fFd); + Rtools::Catch2Cerr(__func__, + [this](){ Server().RemovePollHandler(fFd); } ); + ::close(fFd); } } diff --git a/tools/src/librw11/Rw11VirtTermTcp.cpp b/tools/src/librw11/Rw11VirtTermTcp.cpp index eb5938bf..9a883841 100644 --- a/tools/src/librw11/Rw11VirtTermTcp.cpp +++ b/tools/src/librw11/Rw11VirtTermTcp.cpp @@ -1,4 +1,4 @@ -// $Id: Rw11VirtTermTcp.cpp 1049 2018-09-22 13:56:52Z mueller $ +// $Id: Rw11VirtTermTcp.cpp 1059 2018-10-27 10:34:16Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2018-10-27 1059 1.0.7 coverity fixup (uncaught exception in dtor) // 2017-04-15 875 1.0.6 Open(): set default scheme // 2017-04-07 868 1.0.5 Dump(): add detail arg // 2014-08-22 584 1.0.4 use nullptr @@ -37,6 +38,7 @@ #include "librtools/RosFill.hpp" #include "librtools/RlogMsg.hpp" +#include "librtools/Rtools.hpp" #include "Rw11VirtTermTcp.hpp" @@ -104,12 +106,14 @@ Rw11VirtTermTcp::Rw11VirtTermTcp(Rw11Unit* punit) Rw11VirtTermTcp::~Rw11VirtTermTcp() { if (fFdListen > 2) { - Server().RemovePollHandler(fFdListen); - close(fFdListen); + Rtools::Catch2Cerr(__func__, + [this](){ Server().RemovePollHandler(fFdListen); } ); + ::close(fFdListen); } if (Connected()) { - Server().RemovePollHandler(fFd); - close(fFd); + Rtools::Catch2Cerr(__func__, + [this](){ Server().RemovePollHandler(fFd); } ); + ::close(fFd); } }