Skip to contentSkip to conversation

tls: Ensure callbacks are available before using them

PATCH New Marcel Holtmann 1 participant 1 message Jan 3, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 tls: Ensure callbacks are available before using them

The common callbacks for TLS ready, disconnect and transmission of packets are required to be set for any l_tls object. The app_data callback is made optional in case implementations want to provide an out-of-band data path.

---
 ell/tls.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
ell/tls.c +5 -1
index 687797f1e466..207f6c3ae40f 100644
@@ -3357,6 +3357,9 @@ LIB_EXPORT struct l_tls *l_tls_new(bool server,
 	if (!l_key_is_supported(L_KEY_FEATURE_CRYPTO))
 		return NULL;
 
+	if (!tx_handler || !ready_handler || !disconnect_handler)
+		return NULL;
+
 	tls = l_new(struct l_tls, 1);
 	tls->server = server;
 	tls->rx = app_data_handler;
@@ -3561,7 +3564,8 @@ bool tls_handle_message(struct l_tls *tls, const uint8_t *message,
 			return true;
 
 		tls->in_callback = true;
-		tls->rx(message, len, tls->user_data);
+		if (tls->rx)
+			tls->rx(message, len, tls->user_data);
 		tls->in_callback = false;
 
 		if (tls->pending_destroy) {
Signature · 1 line
2.39.0