Repository: qpid-proton Updated Branches: refs/heads/master a8974a320 -> 5b227bbfb
PROTON-1122:: c++ Fix issues raised by coverity. One issue was a null dereference, which would core dump if an empty string is set as an address in link_options. See: https://scan4.coverity.com/reports.htm#v14284/p10556/fileInstanceId=8369775&defectInstanceId=1901068&mergedDefectId=122279&eventId=1901068-29 Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/5b227bbf Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/5b227bbf Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/5b227bbf Branch: refs/heads/master Commit: 5b227bbfbbd6f4f71758f567cbf178d6e6df0a21 Parents: a8974a3 Author: Alan Conway <[email protected]> Authored: Mon Feb 1 15:37:43 2016 -0500 Committer: Alan Conway <[email protected]> Committed: Mon Feb 1 17:20:31 2016 -0500 ---------------------------------------------------------------------- proton-c/bindings/cpp/include/proton/io.hpp | 2 ++ proton-c/bindings/cpp/src/interop_test.cpp | 5 ++++- proton-c/bindings/cpp/src/link_options.cpp | 5 ++--- proton-c/bindings/cpp/src/posix/io.cpp | 2 ++ proton-c/bindings/cpp/src/types.cpp | 8 ++++++++ proton-c/bindings/cpp/src/uuid.cpp | 2 +- proton-c/bindings/cpp/src/windows/io.cpp | 2 ++ 7 files changed, 21 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5b227bbf/proton-c/bindings/cpp/include/proton/io.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/io.hpp b/proton-c/bindings/cpp/include/proton/io.hpp index 0037c72..8bead5a 100644 --- a/proton-c/bindings/cpp/include/proton/io.hpp +++ b/proton-c/bindings/cpp/include/proton/io.hpp @@ -109,6 +109,8 @@ class socket_engine : public connection_engine { /// Create socket engine connected to url. PN_CPP_EXTERN socket_engine(const url&, handler&, const connection_options& = no_opts); + PN_CPP_EXTERN ~socket_engine(); + /// Get the socket descriptor. descriptor socket() const { return socket_; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5b227bbf/proton-c/bindings/cpp/src/interop_test.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/interop_test.cpp b/proton-c/bindings/cpp/src/interop_test.cpp index fe2d58c..168677b 100644 --- a/proton-c/bindings/cpp/src/interop_test.cpp +++ b/proton-c/bindings/cpp/src/interop_test.cpp @@ -111,7 +111,10 @@ void test_value_conversions() { int main(int argc, char** argv) { int failed = 0; - if (argc != 2) FAIL("Usage: " << argv[0] << " tests-dir"); + if (argc != 2) { + cerr << "Usage: " << argv[0] << " tests-dir" << endl; + return 1; + } tests_dir = argv[1]; RUN_TEST(failed, test_data_ostream()); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5b227bbf/proton-c/bindings/cpp/src/link_options.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/link_options.cpp b/proton-c/bindings/cpp/src/link_options.cpp index 7364c59..3fc694b 100644 --- a/proton-c/bindings/cpp/src/link_options.cpp +++ b/proton-c/bindings/cpp/src/link_options.cpp @@ -74,11 +74,10 @@ class link_options::impl { if (l.state() & endpoint::LOCAL_UNINIT) { bool sender = !l.receiver(); if (local_address.set) { - const char *addr = local_address.value.empty() ? NULL : local_address.value.c_str(); if (sender) - l.local_target().address(addr); + l.local_target().address(local_address.value); else - l.local_source().address(addr); + l.local_source().address(local_address.value); } if (delivery_mode.set) { switch (delivery_mode.value) { http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5b227bbf/proton-c/bindings/cpp/src/posix/io.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/posix/io.cpp b/proton-c/bindings/cpp/src/posix/io.cpp index 26034a6..0f7a3f9 100644 --- a/proton-c/bindings/cpp/src/posix/io.cpp +++ b/proton-c/bindings/cpp/src/posix/io.cpp @@ -74,6 +74,8 @@ socket_engine::socket_engine(const url& u, handler& h, const connection_options& init(); } +socket_engine::~socket_engine() {} + std::pair<size_t, bool> socket_engine::io_read(char *buf, size_t size) { ssize_t n = ::read(socket_, buf, size); if (n > 0) return std::make_pair(n, true); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5b227bbf/proton-c/bindings/cpp/src/types.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/types.cpp b/proton-c/bindings/cpp/src/types.cpp index 7a38f12..1ace1a1 100644 --- a/proton-c/bindings/cpp/src/types.cpp +++ b/proton-c/bindings/cpp/src/types.cpp @@ -27,7 +27,15 @@ namespace proton { namespace { +struct ios_guard { + std::ios &guarded; + std::ios old; + ios_guard(std::ios& x) : guarded(x), old(0) { old.copyfmt(guarded); } + ~ios_guard() { guarded.copyfmt(old); } +}; + inline std::ostream& print_segment(std::ostream& o, const amqp_uuid& u, size_t begin, size_t end, const char* sep="") { + ios_guard restore_flags(o); for (const char* p = &u[begin]; p < &u[end]; ++p) o << std::setw(2) << std::setfill('0') << (int(*p) & 0xff); return o << sep; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5b227bbf/proton-c/bindings/cpp/src/uuid.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/uuid.cpp b/proton-c/bindings/cpp/src/uuid.cpp index 32e11ac..6e8367f 100644 --- a/proton-c/bindings/cpp/src/uuid.cpp +++ b/proton-c/bindings/cpp/src/uuid.cpp @@ -73,7 +73,7 @@ uuid::uuid() { /// UUID standard format: 8-4-4-4-12 (36 chars, 32 alphanumeric and 4 hypens) std::ostream& operator<<(std::ostream& o, const uuid& u) { - ios_guard guard(o); + ios_guard restore_flags(o); o << std::hex << std::setfill('0'); static const int segments[] = {4,2,2,2,6}; // 1 byte is 2 hex chars. const uint8_t *p = u.bytes; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5b227bbf/proton-c/bindings/cpp/src/windows/io.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/windows/io.cpp b/proton-c/bindings/cpp/src/windows/io.cpp index 32b3d3c..9273f19 100644 --- a/proton-c/bindings/cpp/src/windows/io.cpp +++ b/proton-c/bindings/cpp/src/windows/io.cpp @@ -90,6 +90,8 @@ socket_engine::socket_engine(const url& u, handler& h, const connection_options init(); } +socket_engine::~socket_engine() {} + std::pair<size_t, bool> socket_engine::io_read(char *buf, size_t size) { int n = ::recv(socket_, buf, size, 0); if (n > 0) return std::make_pair(n, true); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
