diff options
author | Pierre Ossman <ossman@cendio.se> | 2024-11-25 20:33:40 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2024-11-26 10:10:31 +0100 |
commit | 5c14cd9f7ca1aeb19a7a69ab44e94f025ad39bf4 (patch) | |
tree | 065c04c93c2354a259cb2eb8cb61d9d5063a71ac /common/rdr/TLSInStream.cxx | |
parent | 1cc5bb27701684d196ae5b35208e573fb0a0af2a (diff) | |
download | tigervnc-5c14cd9f7ca1aeb19a7a69ab44e94f025ad39bf4.tar.gz tigervnc-5c14cd9f7ca1aeb19a7a69ab44e94f025ad39bf4.zip |
Don't save exceptions as std::exception
That type is not guaranteed to preserve anything useful at all. Instead,
try to either preserve a more specific type, or use std::runtime_error
which at least has a guaranteed message.
Diffstat (limited to 'common/rdr/TLSInStream.cxx')
-rw-r--r-- | common/rdr/TLSInStream.cxx | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/common/rdr/TLSInStream.cxx b/common/rdr/TLSInStream.cxx index 7c867e88..ee2739f4 100644 --- a/common/rdr/TLSInStream.cxx +++ b/common/rdr/TLSInStream.cxx @@ -64,7 +64,7 @@ ssize_t TLSInStream::pull(gnutls_transport_ptr_t str, void* data, size_t size) } catch (std::exception& e) { vlog.error("Failure reading TLS data: %s", e.what()); gnutls_transport_set_errno(self->session, EINVAL); - self->saved_exception = new std::exception(e); + self->saved_exception = new std::runtime_error(e.what()); return -1; } @@ -117,8 +117,12 @@ size_t TLSInStream::readTLS(uint8_t* buf, size_t len) break; }; - if (n == GNUTLS_E_PULL_ERROR) - throw *saved_exception; + if (n == GNUTLS_E_PULL_ERROR) { + if (dynamic_cast<socket_error*>(saved_exception)) + throw *dynamic_cast<socket_error*>(saved_exception); + else + throw std::runtime_error(saved_exception->what()); + } if (n < 0) throw tls_error("readTLS", n); |