summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-09-08 18:15:32 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-09-08 18:15:32 (GMT)
commit3e1347d378e7ff0e21fb53b61e0317b8dfe52fc9 (patch)
tree1932b705551e4790c2f5c7fb0f9b7d80785d2225 /src
parent1430874c1ce9d5e38a23bf27049ebc5f6a6619bb (diff)
Used the SSL link with more care.
Diffstat (limited to 'src')
-rw-r--r--src/analysis/binary.c30
-rw-r--r--src/analysis/db/client.c52
2 files changed, 59 insertions, 23 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 5d72c41..070e175 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -1102,12 +1102,19 @@ bool _g_loaded_binary_add_to_collection(GLoadedBinary *binary, GDbItem *item, bo
tls_fd = g_hub_client_get_ssl_fd(client);
- result = g_db_collection_pack(collec, &out_pbuf, DBA_ADD_ITEM, item);
+ if (tls_fd == NULL)
+ result = false;
- if (result)
- result = ssl_send_packed_buffer(&out_pbuf, tls_fd);
+ else
+ {
+ result = g_db_collection_pack(collec, &out_pbuf, DBA_ADD_ITEM, item);
- g_hub_client_put_ssl_fd(client, tls_fd);
+ if (result)
+ result = ssl_send_packed_buffer(&out_pbuf, tls_fd);
+
+ g_hub_client_put_ssl_fd(client, tls_fd);
+
+ }
exit_packed_buffer(&out_pbuf);
@@ -1171,12 +1178,19 @@ bool _g_loaded_binary_remove_from_collection(GLoadedBinary *binary, DBFeatures f
tls_fd = g_hub_client_get_ssl_fd(client);
- result = g_db_collection_pack(collec, &out_pbuf, DBA_REM_ITEM, item);
+ if (tls_fd == NULL)
+ result = false;
+
+ else
+ {
+ result = g_db_collection_pack(collec, &out_pbuf, DBA_REM_ITEM, item);
- if (result)
- result = ssl_send_packed_buffer(&out_pbuf, tls_fd);
+ if (result)
+ result = ssl_send_packed_buffer(&out_pbuf, tls_fd);
+
+ g_hub_client_put_ssl_fd(client, tls_fd);
- g_hub_client_put_ssl_fd(client, tls_fd);
+ }
exit_packed_buffer(&out_pbuf);
diff --git a/src/analysis/db/client.c b/src/analysis/db/client.c
index 329d57d..3197a8c 100644
--- a/src/analysis/db/client.c
+++ b/src/analysis/db/client.c
@@ -900,12 +900,18 @@ SSL *g_hub_client_get_ssl_fd(GHubClient *client)
result = client->tls_fd;
+ if (result == NULL)
+ g_mutex_unlock(&client->sending_lock);
+
+ else
+ {
#ifndef NDEBUG
- ret = SSL_up_ref(result);
- assert(ret == 1);
+ ret = SSL_up_ref(result);
+ assert(ret == 1);
#else
- SSL_up_ref(result);
+ SSL_up_ref(result);
#endif
+ }
return result;
@@ -950,17 +956,25 @@ bool g_hub_client_save(GHubClient *client)
{
bool result; /* Bilan partiel à remonter */
packed_buffer out_pbuf; /* Tampon d'émission */
+ SSL *tls_fd; /* Canal de communication SSL */
init_packed_buffer(&out_pbuf);
- g_hub_client_get_ssl_fd(client);
+ tls_fd = g_hub_client_get_ssl_fd(client);
- result = extend_packed_buffer(&out_pbuf, (uint32_t []) { DBC_SAVE }, sizeof(uint32_t), true);
+ if (tls_fd == NULL)
+ result = false;
- if (result)
- result = ssl_send_packed_buffer(&out_pbuf, client->tls_fd);
+ else
+ {
+ result = extend_packed_buffer(&out_pbuf, (uint32_t []) { DBC_SAVE }, sizeof(uint32_t), true);
+
+ if (result)
+ result = ssl_send_packed_buffer(&out_pbuf, tls_fd);
- g_hub_client_put_ssl_fd(client, client->tls_fd);
+ g_hub_client_put_ssl_fd(client, tls_fd);
+
+ }
exit_packed_buffer(&out_pbuf);
@@ -986,20 +1000,28 @@ bool g_hub_client_set_last_active(GHubClient *client, timestamp_t timestamp)
{
bool result; /* Bilan partiel à remonter */
packed_buffer out_pbuf; /* Tampon d'émission */
+ SSL *tls_fd; /* Canal de communication SSL */
init_packed_buffer(&out_pbuf);
- g_hub_client_get_ssl_fd(client);
+ tls_fd = g_hub_client_get_ssl_fd(client);
+
+ if (tls_fd == NULL)
+ result = false;
- result = extend_packed_buffer(&out_pbuf, (uint32_t []) { DBC_SET_LAST_ACTIVE }, sizeof(uint32_t), true);
+ else
+ {
+ result = extend_packed_buffer(&out_pbuf, (uint32_t []) { DBC_SET_LAST_ACTIVE }, sizeof(uint32_t), true);
- if (result)
- result = pack_timestamp(&timestamp, &out_pbuf);
+ if (result)
+ result = pack_timestamp(&timestamp, &out_pbuf);
- if (result)
- result = ssl_send_packed_buffer(&out_pbuf, client->tls_fd);
+ if (result)
+ result = ssl_send_packed_buffer(&out_pbuf, tls_fd);
- g_hub_client_put_ssl_fd(client, client->tls_fd);
+ g_hub_client_put_ssl_fd(client, tls_fd);
+
+ }
exit_packed_buffer(&out_pbuf);