From 895b751c92775f7610869a205d58a0a7c98632e0 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 22 Nov 2024 14:27:02 +0100 Subject: [PATCH] Capitalize some more logging and exceptions --- common/network/Socket.cxx | 6 +++--- common/network/TcpSocket.cxx | 18 +++++++++--------- common/network/UnixSocket.cxx | 6 +++--- common/rdr/AESInStream.cxx | 2 +- common/rdr/ZlibInStream.cxx | 4 ++-- common/rdr/ZlibOutStream.cxx | 2 +- common/rfb/CConnection.cxx | 8 ++++---- common/rfb/CSecurityDH.cxx | 8 ++++---- common/rfb/CSecurityMSLogonII.cxx | 8 ++++---- common/rfb/CSecurityRSAAES.cxx | 26 +++++++++++++------------- common/rfb/CSecurityTLS.cxx | 6 +++--- common/rfb/ClientParams.cxx | 2 +- common/rfb/Configuration.cxx | 2 +- common/rfb/Hostname.h | 6 +++--- common/rfb/LogWriter.cxx | 6 +++--- common/rfb/PixelFormat.cxx | 4 ++-- common/rfb/SConnection.cxx | 16 ++++++++-------- common/rfb/SMsgReader.cxx | 6 +++--- common/rfb/SSecurityRSAAES.cxx | 30 +++++++++++++++--------------- common/rfb/ServerParams.cxx | 2 +- common/rfb/TightDecoder.cxx | 8 ++++---- common/rfb/VNCServerST.cxx | 28 ++++++++++++++-------------- common/rfb/obfuscate.cxx | 2 +- 23 files changed, 103 insertions(+), 103 deletions(-) diff --git a/common/network/Socket.cxx b/common/network/Socket.cxx index 879a63d0..0a35e267 100644 --- a/common/network/Socket.cxx +++ b/common/network/Socket.cxx @@ -55,7 +55,7 @@ void network::initSockets() { WSADATA initResult; if (WSAStartup(requiredVersion, &initResult) != 0) - throw rdr::socket_error("unable to initialise Winsock2", errorNumber); + throw rdr::socket_error("Unable to initialise Winsock2", errorNumber); #else signal(SIGPIPE, SIG_IGN); #endif @@ -163,7 +163,7 @@ Socket* SocketListener::accept() { // Accept an incoming connection if ((new_sock = ::accept(fd, nullptr, nullptr)) < 0) - throw rdr::socket_error("unable to accept new connection", errorNumber); + throw rdr::socket_error("Unable to accept new connection", errorNumber); // Create the socket object & check connection is allowed Socket* s = createSocket(new_sock); @@ -181,7 +181,7 @@ void SocketListener::listen(int sock) if (::listen(sock, 5) < 0) { int e = errorNumber; closesocket(sock); - throw rdr::socket_error("unable to set socket to listening mode", e); + throw rdr::socket_error("Unable to set socket to listening mode", e); } fd = sock; diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index e37861f4..c5b86543 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -85,15 +85,15 @@ int network::findFreeTcpPort (void) addr.sin_addr.s_addr = INADDR_ANY; if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0) - throw socket_error("unable to create socket", errorNumber); + throw socket_error("Unable to create socket", errorNumber); addr.sin_port = 0; if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) < 0) - throw socket_error("unable to find free port", errorNumber); + throw socket_error("Unable to find free port", errorNumber); socklen_t n = sizeof(addr); if (getsockname (sock, (struct sockaddr *)&addr, &n) < 0) - throw socket_error("unable to get port number", errorNumber); + throw socket_error("Unable to get port number", errorNumber); closesocket (sock); return ntohs(addr.sin_port); @@ -137,7 +137,7 @@ TcpSocket::TcpSocket(const char *host, int port) hints.ai_next = nullptr; if ((result = getaddrinfo(host, nullptr, &hints, &ai)) != 0) { - throw getaddrinfo_error("unable to resolve host by name", result); + throw getaddrinfo_error("Unable to resolve host by name", result); } sock = -1; @@ -178,7 +178,7 @@ TcpSocket::TcpSocket(const char *host, int port) if (sock == -1) { err = errorNumber; freeaddrinfo(ai); - throw socket_error("unable to create socket", err); + throw socket_error("Unable to create socket", err); } /* Attempt to connect to the remote host */ @@ -205,7 +205,7 @@ TcpSocket::TcpSocket(const char *host, int port) if (err == 0) throw std::runtime_error("No useful address for host"); else - throw socket_error("unable to connect to socket", err); + throw socket_error("Unable to connect to socket", err); } // Take proper ownership of the socket @@ -610,7 +610,7 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { parts = rfb::split(&p[1], '/'); if (parts.size() > 2) - throw std::invalid_argument("invalid filter specified"); + throw std::invalid_argument("Invalid filter specified"); if (parts[0].empty()) { // Match any address @@ -658,7 +658,7 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { pattern.prefixlen = 128; break; default: - throw std::runtime_error("unknown address family"); + throw std::runtime_error("Unknown address family"); } } } @@ -666,7 +666,7 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { family = pattern.address.u.sa.sa_family; if (pattern.prefixlen > (family == AF_INET ? 32: 128)) - throw std::invalid_argument(rfb::format("invalid prefix length for " + throw std::invalid_argument(rfb::format("Invalid prefix length for " "filter address: %u", pattern.prefixlen)); diff --git a/common/network/UnixSocket.cxx b/common/network/UnixSocket.cxx index fb017a53..48561245 100644 --- a/common/network/UnixSocket.cxx +++ b/common/network/UnixSocket.cxx @@ -53,12 +53,12 @@ UnixSocket::UnixSocket(const char *path) socklen_t salen; if (strlen(path) >= sizeof(addr.sun_path)) - throw socket_error("socket path is too long", ENAMETOOLONG); + throw socket_error("Socket path is too long", ENAMETOOLONG); // - Create a socket sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock == -1) - throw socket_error("unable to create socket", errno); + throw socket_error("Unable to create socket", errno); // - Attempt to connect memset(&addr, 0, sizeof(addr)); @@ -119,7 +119,7 @@ UnixListener::UnixListener(const char *path, int mode) int err, result; if (strlen(path) >= sizeof(addr.sun_path)) - throw socket_error("socket path is too long", ENAMETOOLONG); + throw socket_error("Socket path is too long", ENAMETOOLONG); // - Create a socket if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) diff --git a/common/rdr/AESInStream.cxx b/common/rdr/AESInStream.cxx index 3a56ef73..a4890899 100644 --- a/common/rdr/AESInStream.cxx +++ b/common/rdr/AESInStream.cxx @@ -68,7 +68,7 @@ bool AESInStream::fillBuffer() EAX_DIGEST(&eaxCtx256, aes256_encrypt, 16, macComputed); } if (memcmp(mac, macComputed, 16) != 0) - throw std::runtime_error("AESInStream: failed to authenticate message"); + throw std::runtime_error("AESInStream: Failed to authenticate message"); in->setptr(2 + length + 16); end += length; diff --git a/common/rdr/ZlibInStream.cxx b/common/rdr/ZlibInStream.cxx index c9f8aeca..57aa1e36 100644 --- a/common/rdr/ZlibInStream.cxx +++ b/common/rdr/ZlibInStream.cxx @@ -49,7 +49,7 @@ void ZlibInStream::flushUnderlying() { while (bytesIn > 0) { if (!hasData(1)) - throw std::runtime_error("ZlibInStream: failed to flush remaining stream data"); + throw std::runtime_error("ZlibInStream: Failed to flush remaining stream data"); skip(avail()); } @@ -91,7 +91,7 @@ void ZlibInStream::deinit() bool ZlibInStream::fillBuffer() { if (!underlying) - throw std::runtime_error("ZlibInStream overrun: no underlying stream"); + throw std::runtime_error("ZlibInStream overrun: No underlying stream"); zs->next_out = (uint8_t*)end; zs->avail_out = availSpace(); diff --git a/common/rdr/ZlibOutStream.cxx b/common/rdr/ZlibOutStream.cxx index 5079c723..73b5d459 100644 --- a/common/rdr/ZlibOutStream.cxx +++ b/common/rdr/ZlibOutStream.cxx @@ -112,7 +112,7 @@ void ZlibOutStream::deflate(int flush) int rc; if (!underlying) - throw std::runtime_error("ZlibOutStream: underlying OutStream has not been set"); + throw std::runtime_error("ZlibOutStream: Underlying OutStream has not been set"); if ((flush == Z_NO_FLUSH) && (zs->avail_in == 0)) return; diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index e8451337..2c347710 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -147,11 +147,11 @@ bool CConnection::processMsg() case RFBSTATE_INITIALISATION: return processInitMsg(); break; case RFBSTATE_NORMAL: return reader_->readMsg(); break; case RFBSTATE_CLOSING: - throw std::logic_error("CConnection::processMsg: called while closing"); + throw std::logic_error("CConnection::processMsg: Called while closing"); case RFBSTATE_UNINITIALISED: - throw std::logic_error("CConnection::processMsg: not initialised yet?"); + throw std::logic_error("CConnection::processMsg: Not initialised yet?"); default: - throw std::logic_error("CConnection::processMsg: invalid state"); + throw std::logic_error("CConnection::processMsg: Invalid state"); } } @@ -172,7 +172,7 @@ bool CConnection::processVersionMsg() if (sscanf(verStr, "RFB %03d.%03d\n", &majorVersion, &minorVersion) != 2) { state_ = RFBSTATE_INVALID; - throw protocol_error("reading version failed: not an RFB server?"); + throw protocol_error("Reading version failed, not an RFB server?"); } server.setVersion(majorVersion, minorVersion); diff --git a/common/rfb/CSecurityDH.cxx b/common/rfb/CSecurityDH.cxx index d8308cbf..2f0365a6 100644 --- a/common/rfb/CSecurityDH.cxx +++ b/common/rfb/CSecurityDH.cxx @@ -112,7 +112,7 @@ void CSecurityDH::writeCredentials() std::vector bBytes(keyLength); if (!rs.hasData(keyLength)) - throw std::runtime_error("failed to generate DH private key"); + throw std::runtime_error("Failed to generate DH private key"); rs.readBytes(bBytes.data(), bBytes.size()); nettle_mpz_set_str_256_u(b, bBytes.size(), bBytes.data()); mpz_powm(k, A, b, p); @@ -132,13 +132,13 @@ void CSecurityDH::writeCredentials() uint8_t buf[128]; if (!rs.hasData(128)) - throw std::runtime_error("failed to generate random padding"); + throw std::runtime_error("Failed to generate random padding"); rs.readBytes(buf, 128); if (username.size() >= 64) - throw std::out_of_range("username is too long"); + throw std::out_of_range("Username is too long"); memcpy(buf, username.c_str(), username.size() + 1); if (password.size() >= 64) - throw std::out_of_range("password is too long"); + throw std::out_of_range("Password is too long"); memcpy(buf + 64, password.c_str(), password.size() + 1); aes128_encrypt(&aesCtx, 128, buf, buf); diff --git a/common/rfb/CSecurityMSLogonII.cxx b/common/rfb/CSecurityMSLogonII.cxx index 85736b44..a5a99286 100644 --- a/common/rfb/CSecurityMSLogonII.cxx +++ b/common/rfb/CSecurityMSLogonII.cxx @@ -100,7 +100,7 @@ void CSecurityMSLogonII::writeCredentials() std::vector bBytes(8); if (!rs.hasData(8)) - throw std::runtime_error("failed to generate DH private key"); + throw std::runtime_error("Failed to generate DH private key"); rs.readBytes(bBytes.data(), bBytes.size()); nettle_mpz_set_str_256_u(b, bBytes.size(), bBytes.data()); mpz_powm(k, A, b, p); @@ -122,14 +122,14 @@ void CSecurityMSLogonII::writeCredentials() } if (!rs.hasData(256 + 64)) - throw std::runtime_error("failed to generate random padding"); + throw std::runtime_error("Failed to generate random padding"); rs.readBytes(user, 256); rs.readBytes(pass, 64); if (username.size() >= 256) - throw std::out_of_range("username is too long"); + throw std::out_of_range("Username is too long"); memcpy(user, username.c_str(), username.size() + 1); if (password.size() >= 64) - throw std::out_of_range("password is too long"); + throw std::out_of_range("Password is too long"); memcpy(pass, password.c_str(), password.size() + 1); // DES-CBC with the original key as IV, and the reversed one as the DES key diff --git a/common/rfb/CSecurityRSAAES.cxx b/common/rfb/CSecurityRSAAES.cxx index 96fd20cd..416eaa2d 100644 --- a/common/rfb/CSecurityRSAAES.cxx +++ b/common/rfb/CSecurityRSAAES.cxx @@ -134,7 +134,7 @@ static void random_func(void* ctx, size_t length, uint8_t* dst) { rdr::RandomStream* rs = (rdr::RandomStream*)ctx; if (!rs->hasData(length)) - throw std::runtime_error("failed to generate random"); + throw std::runtime_error("Failed to generate random"); rs->readBytes(dst, length); } @@ -155,7 +155,7 @@ void CSecurityRSAAES::writePublicKey() if (!rsa_generate_keypair(&clientPublicKey, &clientKey, &rs, random_func, nullptr, nullptr, clientKeyLength, 0)) - throw std::runtime_error("failed to generate key"); + throw std::runtime_error("Failed to generate key"); clientKeyN = new uint8_t[rsaKeySize]; clientKeyE = new uint8_t[rsaKeySize]; nettle_mpz_get_str_256(rsaKeySize, clientKeyN, clientPublicKey.n); @@ -174,9 +174,9 @@ bool CSecurityRSAAES::readPublicKey() is->setRestorePoint(); serverKeyLength = is->readU32(); if (serverKeyLength < MinKeyLength) - throw protocol_error("server key is too short"); + throw protocol_error("Server key is too short"); if (serverKeyLength > MaxKeyLength) - throw protocol_error("server key is too long"); + throw protocol_error("Server key is too long"); size_t size = (serverKeyLength + 7) / 8; if (!is->hasDataOrRestore(size * 2)) return false; @@ -189,7 +189,7 @@ bool CSecurityRSAAES::readPublicKey() nettle_mpz_set_str_256_u(serverKey.n, size, serverKeyN); nettle_mpz_set_str_256_u(serverKey.e, size, serverKeyE); if (!rsa_public_key_prepare(&serverKey)) - throw protocol_error("server key is invalid"); + throw protocol_error("Server key is invalid"); return true; } @@ -222,7 +222,7 @@ void CSecurityRSAAES::writeRandom() { rdr::OutStream* os = cc->getOutStream(); if (!rs.hasData(keySize / 8)) - throw std::runtime_error("failed to generate random"); + throw std::runtime_error("Failed to generate random"); rs.readBytes(clientRandom, keySize / 8); mpz_t x; mpz_init(x); @@ -236,7 +236,7 @@ void CSecurityRSAAES::writeRandom() } if (!res) { mpz_clear(x); - throw std::runtime_error("failed to encrypt random"); + throw std::runtime_error("Failed to encrypt random"); } uint8_t* buffer = new uint8_t[serverKey.size]; nettle_mpz_get_str_256(serverKey.size, buffer, x); @@ -255,7 +255,7 @@ bool CSecurityRSAAES::readRandom() is->setRestorePoint(); size_t size = is->readU16(); if (size != clientKey.size) - throw protocol_error("client key length doesn't match"); + throw protocol_error("Client key length doesn't match"); if (!is->hasDataOrRestore(size)) return false; is->clearRestorePoint(); @@ -268,7 +268,7 @@ bool CSecurityRSAAES::readRandom() if (!rsa_decrypt(&clientKey, &randomSize, serverRandom, x) || randomSize != (size_t)keySize / 8) { mpz_clear(x); - throw protocol_error("failed to decrypt server random"); + throw protocol_error("Failed to decrypt server random"); } mpz_clear(x); return true; @@ -397,7 +397,7 @@ bool CSecurityRSAAES::readHash() sha256_digest(&ctx, hashSize, realHash); } if (memcmp(hash, realHash, hashSize) != 0) - throw protocol_error("hash doesn't match"); + throw protocol_error("Hash doesn't match"); return true; } @@ -427,7 +427,7 @@ bool CSecurityRSAAES::readSubtype() return false; subtype = rais->readU8(); if (subtype != secTypeRA2UserPass && subtype != secTypeRA2Pass) - throw protocol_error("unknown RSA-AES subtype"); + throw protocol_error("Unknown RSA-AES subtype"); return true; } @@ -443,7 +443,7 @@ void CSecurityRSAAES::writeCredentials() if (subtype == secTypeRA2UserPass) { if (username.size() > 255) - throw std::out_of_range("username is too long"); + throw std::out_of_range("Username is too long"); raos->writeU8(username.size()); raos->writeBytes((const uint8_t*)username.data(), username.size()); } else { @@ -451,7 +451,7 @@ void CSecurityRSAAES::writeCredentials() } if (password.size() > 255) - throw std::out_of_range("password is too long"); + throw std::out_of_range("Password is too long"); raos->writeU8(password.size()); raos->writeBytes((const uint8_t*)password.data(), password.size()); raos->flush(); diff --git a/common/rfb/CSecurityTLS.cxx b/common/rfb/CSecurityTLS.cxx index 9072ce50..bb7e3879 100644 --- a/common/rfb/CSecurityTLS.cxx +++ b/common/rfb/CSecurityTLS.cxx @@ -312,12 +312,12 @@ void CSecurityTLS::checkSession() return; if (gnutls_certificate_type_get(session) != GNUTLS_CRT_X509) - throw protocol_error("unsupported certificate type"); + throw protocol_error("Unsupported certificate type"); err = gnutls_certificate_verify_peers2(session, &status); if (err != 0) { vlog.error("Server certificate verification failed: %s", gnutls_strerror(err)); - throw rdr::tls_error("server certificate verification()", err); + throw rdr::tls_error("Server certificate verification()", err); } if (status != 0) { @@ -360,7 +360,7 @@ void CSecurityTLS::checkSession() cert_list = gnutls_certificate_get_peers(session, &cert_list_size); if (!cert_list_size) - throw protocol_error("empty certificate chain"); + throw protocol_error("Empty certificate chain"); /* Process only server's certificate, not issuer's certificate */ gnutls_x509_crt_t crt; diff --git a/common/rfb/ClientParams.cxx b/common/rfb/ClientParams.cxx index b86cc97f..e5fd105e 100644 --- a/common/rfb/ClientParams.cxx +++ b/common/rfb/ClientParams.cxx @@ -76,7 +76,7 @@ void ClientParams::setPF(const PixelFormat& pf) pf_ = pf; if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32) - throw std::invalid_argument("setPF: not 8, 16 or 32 bpp?"); + throw std::invalid_argument("setPF: Not 8, 16 or 32 bpp?"); } void ClientParams::setName(const char* name) diff --git a/common/rfb/Configuration.cxx b/common/rfb/Configuration.cxx index 44d42a88..72947df1 100644 --- a/common/rfb/Configuration.cxx +++ b/common/rfb/Configuration.cxx @@ -294,7 +294,7 @@ BoolParameter::setParam(const char* v) { || strcasecmp(v, "false") == 0 || strcasecmp(v, "no") == 0) setParam(false); else { - vlog.error("Bool parameter %s: invalid value '%s'", getName(), v); + vlog.error("Bool parameter %s: Invalid value '%s'", getName(), v); return false; } diff --git a/common/rfb/Hostname.h b/common/rfb/Hostname.h index de4a330e..f43e5067 100644 --- a/common/rfb/Hostname.h +++ b/common/rfb/Hostname.h @@ -62,7 +62,7 @@ namespace rfb { hostStart = &hi[1]; hostEnd = strchr(hostStart, ']'); if (hostEnd == nullptr) - throw std::invalid_argument("unmatched [ in host"); + throw std::invalid_argument("Unmatched [ in host"); portStart = hostEnd + 1; if (isAllSpace(portStart)) @@ -101,14 +101,14 @@ namespace rfb { char* end; if (portStart[0] != ':') - throw std::invalid_argument("invalid port specified"); + throw std::invalid_argument("Invalid port specified"); if (portStart[1] != ':') *port = strtol(portStart + 1, &end, 10); else *port = strtol(portStart + 2, &end, 10); if (*end != '\0' && ! isAllSpace(end)) - throw std::invalid_argument("invalid port specified"); + throw std::invalid_argument("Invalid port specified"); if ((portStart[1] != ':') && (*port < 100)) *port += basePort; diff --git a/common/rfb/LogWriter.cxx b/common/rfb/LogWriter.cxx index b222d268..8e39d544 100644 --- a/common/rfb/LogWriter.cxx +++ b/common/rfb/LogWriter.cxx @@ -80,7 +80,7 @@ bool LogWriter::setLogParams(const char* params) { std::vector parts; parts = split(params, ':'); if (parts.size() != 3) { - fprintf(stderr,"failed to parse log params:%s\n",params); + fprintf(stderr, "Failed to parse log params:%s\n",params); return false; } int level = atoi(parts[2].c_str()); @@ -88,7 +88,7 @@ bool LogWriter::setLogParams(const char* params) { if (!parts[1].empty()) { logger = Logger::getLogger(parts[1].c_str()); if (!logger) - fprintf(stderr, "no logger found! %s\n", parts[1].c_str()); + fprintf(stderr, "No logger found! %s\n", parts[1].c_str()); } if (parts[0] == "*") { LogWriter* current = log_writers; @@ -101,7 +101,7 @@ bool LogWriter::setLogParams(const char* params) { } else { LogWriter* logwriter = getLogWriter(parts[0].c_str()); if (!logwriter) { - fprintf(stderr, "no logwriter found! %s\n", parts[0].c_str()); + fprintf(stderr, "No logwriter found! %s\n", parts[0].c_str()); } else { logwriter->setLog(logger); logwriter->setLevel(level); diff --git a/common/rfb/PixelFormat.cxx b/common/rfb/PixelFormat.cxx index e312b3c9..1d01790f 100644 --- a/common/rfb/PixelFormat.cxx +++ b/common/rfb/PixelFormat.cxx @@ -86,7 +86,7 @@ PixelFormat::PixelFormat(int b, int d, bool e, bool t, redShift(rs), greenShift(gs), blueShift(bs) { if (!isSane()) - throw std::invalid_argument("invalid pixel format"); + throw std::invalid_argument("Invalid pixel format"); updateState(); } @@ -180,7 +180,7 @@ void PixelFormat::read(rdr::InStream* is) } if (!isSane()) - throw protocol_error("invalid pixel format"); + throw protocol_error("Invalid pixel format"); updateState(); } diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx index dc0c1e85..a0a1c373 100644 --- a/common/rfb/SConnection.cxx +++ b/common/rfb/SConnection.cxx @@ -95,14 +95,14 @@ bool SConnection::processMsg() case RFBSTATE_INITIALISATION: return processInitMsg(); break; case RFBSTATE_NORMAL: return reader_->readMsg(); break; case RFBSTATE_QUERYING: - throw std::logic_error("SConnection::processMsg: bogus data from " + throw std::logic_error("SConnection::processMsg: Bogus data from " "client while querying"); case RFBSTATE_CLOSING: - throw std::logic_error("SConnection::processMsg: called while closing"); + throw std::logic_error("SConnection::processMsg: Called while closing"); case RFBSTATE_UNINITIALISED: - throw std::logic_error("SConnection::processMsg: not initialised yet?"); + throw std::logic_error("SConnection::processMsg: Not initialised yet?"); default: - throw std::logic_error("SConnection::processMsg: invalid state"); + throw std::logic_error("SConnection::processMsg: Invalid state"); } } @@ -123,7 +123,7 @@ bool SConnection::processVersionMsg() if (sscanf(verStr, "RFB %03d.%03d\n", &majorVersion, &minorVersion) != 2) { state_ = RFBSTATE_INVALID; - throw protocol_error("reading version failed: not an RFB client?"); + throw protocol_error("Reading version failed, not an RFB client?"); } client.setVersion(majorVersion, minorVersion); @@ -281,7 +281,7 @@ bool SConnection::processInitMsg() void SConnection::handleAuthFailureTimeout(Timer* /*t*/) { if (state_ != RFBSTATE_SECURITY_FAILURE) { - close("SConnection::handleAuthFailureTimeout: invalid state"); + close("SConnection::handleAuthFailureTimeout: Invalid state"); return; } @@ -336,7 +336,7 @@ void SConnection::setAccessRights(AccessRights ar) bool SConnection::accessCheck(AccessRights ar) const { if (state_ < RFBSTATE_QUERYING) - throw std::logic_error("SConnection::accessCheck: invalid state"); + throw std::logic_error("SConnection::accessCheck: Invalid state"); return (accessRights & ar) == ar; } @@ -454,7 +454,7 @@ void SConnection::queryConnection(const char* /*userName*/) void SConnection::approveConnection(bool accept, const char* reason) { if (state_ != RFBSTATE_QUERYING) - throw std::logic_error("SConnection::approveConnection: invalid state"); + throw std::logic_error("SConnection::approveConnection: Invalid state"); if (!client.beforeVersion(3,8) || ssecurity->getType() != secTypeNone) { if (accept) { diff --git a/common/rfb/SMsgReader.cxx b/common/rfb/SMsgReader.cxx index 0497f887..5df11153 100644 --- a/common/rfb/SMsgReader.cxx +++ b/common/rfb/SMsgReader.cxx @@ -106,8 +106,8 @@ bool SMsgReader::readMsg() ret = readQEMUMessage(); break; default: - vlog.error("unknown message type %d", currentMsgType); - throw protocol_error("unknown message type"); + vlog.error("Unknown message type %d", currentMsgType); + throw protocol_error("Unknown message type"); } if (ret) @@ -485,7 +485,7 @@ bool SMsgReader::readQEMUMessage() ret = readQEMUKeyEvent(); break; default: - throw protocol_error(format("unknown QEMU submessage type %d", subType)); + throw protocol_error(format("Unknown QEMU submessage type %d", subType)); } if (!ret) { diff --git a/common/rfb/SSecurityRSAAES.cxx b/common/rfb/SSecurityRSAAES.cxx index 2f26de26..1e5f2384 100644 --- a/common/rfb/SSecurityRSAAES.cxx +++ b/common/rfb/SSecurityRSAAES.cxx @@ -159,18 +159,18 @@ void SSecurityRSAAES::loadPrivateKey() { FILE* file = fopen(keyFile, "rb"); if (!file) - throw rdr::posix_error("failed to open key file", errno); + throw rdr::posix_error("Failed to open key file", errno); fseek(file, 0, SEEK_END); size_t size = ftell(file); if (size == 0 || size > MaxKeyFileSize) { fclose(file); - throw std::runtime_error("size of key file is zero or too big"); + throw std::runtime_error("Size of key file is zero or too big"); } fseek(file, 0, SEEK_SET); std::vector data(size); if (fread(data.data(), 1, data.size(), file) != size) { fclose(file); - throw rdr::posix_error("failed to read key", errno); + throw rdr::posix_error("Failed to read key", errno); } fclose(file); @@ -187,7 +187,7 @@ void SSecurityRSAAES::loadPrivateKey() loadPKCS8Key(der.data(), der.size()); return; } - throw std::runtime_error("failed to import key"); + throw std::runtime_error("Failed to import key"); } void SSecurityRSAAES::loadPKCS1Key(const uint8_t* data, size_t size) @@ -198,7 +198,7 @@ void SSecurityRSAAES::loadPKCS1Key(const uint8_t* data, size_t size) if (!rsa_keypair_from_der(&pub, &serverKey, 0, size, data)) { rsa_private_key_clear(&serverKey); rsa_public_key_clear(&pub); - throw std::runtime_error("failed to import key"); + throw std::runtime_error("Failed to import key"); } serverKeyLength = serverKey.size * 8; serverKeyN = new uint8_t[serverKey.size]; @@ -238,7 +238,7 @@ void SSecurityRSAAES::loadPKCS8Key(const uint8_t* data, size_t size) loadPKCS1Key(i.data, i.length); return; failed: - throw std::runtime_error("failed to import key"); + throw std::runtime_error("Failed to import key"); } bool SSecurityRSAAES::processMsg() @@ -299,9 +299,9 @@ bool SSecurityRSAAES::readPublicKey() is->setRestorePoint(); clientKeyLength = is->readU32(); if (clientKeyLength < MinKeyLength) - throw protocol_error("client key is too short"); + throw protocol_error("Client key is too short"); if (clientKeyLength > MaxKeyLength) - throw protocol_error("client key is too long"); + throw protocol_error("Client key is too long"); size_t size = (clientKeyLength + 7) / 8; if (!is->hasDataOrRestore(size * 2)) return false; @@ -314,7 +314,7 @@ bool SSecurityRSAAES::readPublicKey() nettle_mpz_set_str_256_u(clientKey.n, size, clientKeyN); nettle_mpz_set_str_256_u(clientKey.e, size, clientKeyE); if (!rsa_public_key_prepare(&clientKey)) - throw protocol_error("client key is invalid"); + throw protocol_error("Client key is invalid"); return true; } @@ -322,7 +322,7 @@ static void random_func(void* ctx, size_t length, uint8_t* dst) { rdr::RandomStream* rs = (rdr::RandomStream*)ctx; if (!rs->hasData(length)) - throw std::runtime_error("failed to encrypt random"); + throw std::runtime_error("Failed to encrypt random"); rs->readBytes(dst, length); } @@ -330,7 +330,7 @@ void SSecurityRSAAES::writeRandom() { rdr::OutStream* os = sc->getOutStream(); if (!rs.hasData(keySize / 8)) - throw std::runtime_error("failed to generate random"); + throw std::runtime_error("Failed to generate random"); rs.readBytes(serverRandom, keySize / 8); mpz_t x; mpz_init(x); @@ -344,7 +344,7 @@ void SSecurityRSAAES::writeRandom() } if (!res) { mpz_clear(x); - throw std::runtime_error("failed to encrypt random"); + throw std::runtime_error("Failed to encrypt random"); } uint8_t* buffer = new uint8_t[clientKey.size]; nettle_mpz_get_str_256(clientKey.size, buffer, x); @@ -363,7 +363,7 @@ bool SSecurityRSAAES::readRandom() is->setRestorePoint(); size_t size = is->readU16(); if (size != serverKey.size) - throw protocol_error("server key length doesn't match"); + throw protocol_error("Server key length doesn't match"); if (!is->hasDataOrRestore(size)) return false; is->clearRestorePoint(); @@ -376,7 +376,7 @@ bool SSecurityRSAAES::readRandom() if (!rsa_decrypt(&serverKey, &randomSize, clientRandom, x) || randomSize != (size_t)keySize / 8) { mpz_clear(x); - throw protocol_error("failed to decrypt client random"); + throw protocol_error("Failed to decrypt client random"); } mpz_clear(x); return true; @@ -505,7 +505,7 @@ bool SSecurityRSAAES::readHash() sha256_digest(&ctx, hashSize, realHash); } if (memcmp(hash, realHash, hashSize) != 0) - throw protocol_error("hash doesn't match"); + throw protocol_error("Hash doesn't match"); return true; } diff --git a/common/rfb/ServerParams.cxx b/common/rfb/ServerParams.cxx index 15749ba5..b7432b8f 100644 --- a/common/rfb/ServerParams.cxx +++ b/common/rfb/ServerParams.cxx @@ -73,7 +73,7 @@ void ServerParams::setPF(const PixelFormat& pf) pf_ = pf; if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32) - throw std::invalid_argument("setPF: not 8, 16 or 32 bpp?"); + throw std::invalid_argument("setPF: Not 8, 16 or 32 bpp?"); } void ServerParams::setName(const char* name) diff --git a/common/rfb/TightDecoder.cxx b/common/rfb/TightDecoder.cxx index ccf45a9d..a26c0bfe 100644 --- a/common/rfb/TightDecoder.cxx +++ b/common/rfb/TightDecoder.cxx @@ -104,14 +104,14 @@ bool TightDecoder::readRect(const Rect& r, rdr::InStream* is, // Quit on unsupported compression type. if (comp_ctl > tightMaxSubencoding) - throw protocol_error("TightDecoder: bad subencoding value received"); + throw protocol_error("TightDecoder: Bad subencoding value received"); // "Basic" compression type. int palSize = 0; if (r.width() > TIGHT_MAX_WIDTH) - throw protocol_error(format("TightDecoder: too large rectangle (%d pixels)", r.width())); + throw protocol_error(format("TightDecoder: Too large rectangle (%d pixels)", r.width())); // Possible palette if ((comp_ctl & tightExplicitFilter) != 0) { @@ -143,12 +143,12 @@ bool TightDecoder::readRect(const Rect& r, rdr::InStream* is, break; case tightFilterGradient: if (server.pf().bpp == 8) - throw protocol_error("TightDecoder: invalid BPP for gradient filter"); + throw protocol_error("TightDecoder: Invalid BPP for gradient filter"); break; case tightFilterCopy: break; default: - throw protocol_error("TightDecoder: unknown filter code received"); + throw protocol_error("TightDecoder: Unknown filter code received"); } } diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index f4f48e1e..b99d33b0 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -91,7 +91,7 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) idleTimer(this), disconnectTimer(this), connectTimer(this), msc(0), queuedMsc(0), frameTimer(this) { - slog.debug("creating single-threaded server %s", name.c_str()); + slog.debug("Creating single-threaded server %s", name.c_str()); desktop_->init(this); @@ -104,7 +104,7 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) VNCServerST::~VNCServerST() { - slog.debug("shutting down server %s", name.c_str()); + slog.debug("Shutting down server %s", name.c_str()); // Close any active clients, with appropriate logging & cleanup closeClients("Server shutdown"); @@ -139,7 +139,7 @@ void VNCServerST::addSocket(network::Socket* sock, bool outgoing, AccessRights a // *** do this in getSecurity instead? const char *address = sock->getPeerAddress(); if (blHosts->isBlackmarked(address)) { - connectionsLog.error("blacklisted: %s", address); + connectionsLog.error("Blacklisted: %s", address); try { rdr::OutStream& os = sock->outStream(); @@ -157,7 +157,7 @@ void VNCServerST::addSocket(network::Socket* sock, bool outgoing, AccessRights a return; } - connectionsLog.status("accepted: %s", sock->getPeerEndpoint()); + connectionsLog.status("Accepted: %s", sock->getPeerEndpoint()); // Adjust the exit timers if (rfb::Server::maxConnectionTime && clients.empty()) @@ -191,7 +191,7 @@ void VNCServerST::removeSocket(network::Socket* sock) { clients.remove(*ci); - connectionsLog.status("closed: %s", peer.c_str()); + connectionsLog.status("Closed: %s", peer.c_str()); // - Check that the desktop object is still required if (authClientCount() == 0) @@ -223,7 +223,7 @@ void VNCServerST::processSocketReadEvent(network::Socket* sock) return; } } - throw std::invalid_argument("invalid Socket in VNCServerST"); + throw std::invalid_argument("Invalid Socket in VNCServerST"); } void VNCServerST::processSocketWriteEvent(network::Socket* sock) @@ -236,7 +236,7 @@ void VNCServerST::processSocketWriteEvent(network::Socket* sock) return; } } - throw std::invalid_argument("invalid Socket in VNCServerST"); + throw std::invalid_argument("Invalid Socket in VNCServerST"); } void VNCServerST::blockUpdates() @@ -283,13 +283,13 @@ void VNCServerST::setPixelBuffer(PixelBuffer* pb_, const ScreenSet& layout) screenLayout = ScreenSet(); if (desktopStarted) - throw std::logic_error("setPixelBuffer: null PixelBuffer when desktopStarted?"); + throw std::logic_error("setPixelBuffer: Null PixelBuffer when desktopStarted?"); return; } if (!layout.validate(pb->width(), pb->height())) - throw std::invalid_argument("setPixelBuffer: invalid screen layout"); + throw std::invalid_argument("setPixelBuffer: Invalid screen layout"); screenLayout = layout; @@ -341,9 +341,9 @@ void VNCServerST::setPixelBuffer(PixelBuffer* pb_) void VNCServerST::setScreenLayout(const ScreenSet& layout) { if (!pb) - throw std::logic_error("setScreenLayout: new screen layout without a PixelBuffer"); + throw std::logic_error("setScreenLayout: New screen layout without a PixelBuffer"); if (!layout.validate(pb->width(), pb->height())) - throw std::invalid_argument("setScreenLayout: invalid screen layout"); + throw std::invalid_argument("setScreenLayout: Invalid screen layout"); screenLayout = layout; @@ -705,7 +705,7 @@ void VNCServerST::clientReady(VNCSConnectionST* client, bool shared) if (rfb::Server::disconnectClients && client->accessCheck(AccessNonShared)) { // - Close all the other connected clients - slog.debug("non-shared connection - closing clients"); + slog.debug("Non-shared connection - closing clients"); closeClients("Non-shared connection requested", client->getSock()); } else { // - Refuse this connection if there are existing clients, in addition to @@ -723,7 +723,7 @@ void VNCServerST::clientReady(VNCSConnectionST* client, bool shared) void VNCServerST::startDesktop() { if (!desktopStarted) { - slog.debug("starting desktop"); + slog.debug("Starting desktop"); desktop->start(); if (!pb) throw std::logic_error("SDesktop::start() did not set a valid PixelBuffer"); @@ -745,7 +745,7 @@ void VNCServerST::startDesktop() void VNCServerST::stopDesktop() { if (desktopStarted) { - slog.debug("stopping desktop"); + slog.debug("Stopping desktop"); desktopStarted = false; desktop->stop(); } diff --git a/common/rfb/obfuscate.cxx b/common/rfb/obfuscate.cxx index a88d2822..18a598fe 100644 --- a/common/rfb/obfuscate.cxx +++ b/common/rfb/obfuscate.cxx @@ -58,7 +58,7 @@ std::string rfb::deobfuscate(const uint8_t *data, size_t len) char buf[9]; if (len != 8) - throw std::invalid_argument("bad obfuscated password length"); + throw std::invalid_argument("Bad obfuscated password length"); assert(data != nullptr); -- 2.39.5