diff --git a/CHANGELOG.md b/CHANGELOG.md index aac52f38bbb918b6cdab7c7a1c295d7af3b8fe99..bda3450d8756b1107f0c7d404402f8f1e7a94b78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [0.11.1] - 2020-01-22 + +### Fixed + +- Fix potential crash in AttributeName::tangoHostWithDomain() [#8](https://github.com/tango-controls-hdbpp/libhdbpp-timescale/pull/8) + ## [0.11.0] - 2020-01-21 ### Added diff --git a/src/AttributeName.cpp b/src/AttributeName.cpp index b703ee77efb2edf8ed0d15734a0c64519c53ee30..61b276f69c0ce45c0645a13aff8e28712bacb887 100644 --- a/src/AttributeName.cpp +++ b/src/AttributeName.cpp @@ -94,7 +94,7 @@ const string &AttributeName::tangoHostWithDomain() hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_CANONNAME; - struct addrinfo *result, *rp; + struct addrinfo *result; const int status = getaddrinfo(server_name.c_str(), nullptr, &hints, &result); if (status != 0) @@ -104,9 +104,21 @@ const string &AttributeName::tangoHostWithDomain() return tangoHost(); } - - for (rp = result; rp != nullptr; rp = rp->ai_next) - server_name_with_domain = string(rp->ai_canonname) + tango_host.substr(tango_host.find(':', 0)); + + if (result == nullptr) + { + spdlog::error("Error: Unable to add domain to tango host {}: getaddrinfo didn't return the canonical name (result == nullptr)", tango_host); + return tangoHost(); + } + + if (result->ai_canonname == nullptr) + { + spdlog::error("Error: Unable to add domain to tango host {}: getaddrinfo didn't return the canonical name (result->ai_canonname == nullptr)", tango_host); + freeaddrinfo(result); + return tangoHost(); + } + + server_name_with_domain = string(result->ai_canonname) + tango_host.substr(tango_host.find(':', 0)); freeaddrinfo(result); // all done with this structure _tango_host_with_domain_cache = server_name_with_domain;