Skip to content

Commit

Permalink
Capitalize some more logging and exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
CendioOssman committed Nov 22, 2024
1 parent 9366d8e commit 895b751
Show file tree
Hide file tree
Showing 23 changed files with 103 additions and 103 deletions.
6 changes: 3 additions & 3 deletions common/network/Socket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions common/network/TcpSocket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -658,15 +658,15 @@ 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");
}
}
}

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));

Expand Down
6 changes: 3 additions & 3 deletions common/network/UnixSocket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion common/rdr/AESInStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions common/rdr/ZlibInStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion common/rdr/ZlibOutStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions common/rfb/CConnection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions common/rfb/CSecurityDH.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void CSecurityDH::writeCredentials()

std::vector<uint8_t> 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);
Expand All @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions common/rfb/CSecurityMSLogonII.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void CSecurityMSLogonII::writeCredentials()

std::vector<uint8_t> 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);
Expand All @@ -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
Expand Down
26 changes: 13 additions & 13 deletions common/rfb/CSecurityRSAAES.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -443,15 +443,15 @@ 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 {
raos->writeU8(0);
}

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();
Expand Down
6 changes: 3 additions & 3 deletions common/rfb/CSecurityTLS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/ClientParams.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/Configuration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading

0 comments on commit 895b751

Please sign in to comment.