summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2021-01-16 00:28:18 +0100
committerDirk Engling <erdgeist@erdgeist.org>2021-01-16 00:28:18 +0100
commit38c21730dcc3e83334bf0c719a7b5d63ed6f90e4 (patch)
treedbb94658d6ae1ebe088773c70e0fc561eaec413d
parent0978e237af3f26070b4824e09a7730aad44c3d0d (diff)
Add destructor code for g_sessions in case of shutdown
-rw-r--r--receiver.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/receiver.cpp b/receiver.cpp
index 6be0f8a..44ab3f7 100644
--- a/receiver.cpp
+++ b/receiver.cpp
@@ -121,6 +121,9 @@ public:
121 121
122 ~Session() { 122 ~Session() {
123 mbedtls_gcm_free(&_ctx); 123 mbedtls_gcm_free(&_ctx);
124 if (_fd != -1)
125 ::close(_fd);
126 _fd = -1;
124 } 127 }
125 128
126 int ensure_file() { 129 int ensure_file() {
@@ -296,8 +299,10 @@ int main() {
296 socklen_t peer_len = sizeof(peer); 299 socklen_t peer_len = sizeof(peer);
297 300
298 ssize_t len = recvfrom(sock, packet, sizeof(packet), MSG_WAITALL, (struct sockaddr *) &peer, &peer_len); 301 ssize_t len = recvfrom(sock, packet, sizeof(packet), MSG_WAITALL, (struct sockaddr *) &peer, &peer_len);
299 if (len <= 0) 302 if (len < 0) {
300 errx(-1, "Fatal: recvfrom yields %zd\n", len); 303 errx(-1, "Fatal: recvfrom yields %zd\n", len);
304 g_sessions.clear();
305 }
301 306
302 if (len < MIN_PACKET_SIZE) { 307 if (len < MIN_PACKET_SIZE) {
303 std::cerr << "Skipping short packet" << std::endl; 308 std::cerr << "Skipping short packet" << std::endl;
@@ -312,7 +317,7 @@ int main() {
312 ret = mbedtls_pk_decrypt(&pk, packet + 1 + SESSION_ID_LENGTH, len - 1 - SESSION_ID_LENGTH, 317 ret = mbedtls_pk_decrypt(&pk, packet + 1 + SESSION_ID_LENGTH, len - 1 - SESSION_ID_LENGTH,
313 rsa_plain_text, &olen, sizeof(rsa_plain_text), mbedtls_ctr_drbg_random, &ctr_drbg); 318 rsa_plain_text, &olen, sizeof(rsa_plain_text), mbedtls_ctr_drbg_random, &ctr_drbg);
314 if (ret < 0) { 319 if (ret < 0) {
315 std::cerr << "Error: Failed to decrypt key (error " << -ret << ") for session " << std::hex << session_id; 320 std::cerr << "Error: Failed to decrypt key (error " << -ret << ") for session " << std::hex << session_id << std::endl;
316 break; 321 break;
317 } 322 }
318 323