Module: kamailio
Branch: master
Commit: f08d27c895308e80d13a388b63428ad54178dcfa
URL: 
https://github.com/kamailio/kamailio/commit/f08d27c895308e80d13a388b63428ad54178dcfa

Author: Mattcazz <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2026-07-01T13:00:20+02:00

tls: added null pointer protection to tls_ct_wq_total_bytes() function

When fetching Prometheus metrics, if tls.so is loaded, the TLS module
registers the clear_text_write_queued_bytes statistic in even when TLS
support is disabled (enable_tls=no or not set).

In that case tls_ct_wq_init() is never called and tls_total_ct_wq stays
NULL. When we call prom_dispatch from xhttp_prom with
xhttp_prom_stats=all to query the data, the callback
tls_stats_ct_wq_total_bytes() calls
tls_ct_wq_total_bytes() which dereferences the NULL pointer and causes a
segmentation fault.

---

Modified: src/modules/tls/tls_ct_wrq.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/f08d27c895308e80d13a388b63428ad54178dcfa.diff
Patch: 
https://github.com/kamailio/kamailio/commit/f08d27c895308e80d13a388b63428ad54178dcfa.patch

---

diff --git a/src/modules/tls/tls_ct_wrq.c b/src/modules/tls/tls_ct_wrq.c
index f407e33f29f..0016495f9e1 100644
--- a/src/modules/tls/tls_ct_wrq.c
+++ b/src/modules/tls/tls_ct_wrq.c
@@ -72,6 +72,8 @@ void tls_ct_wq_destroy()
  */
 unsigned int tls_ct_wq_total_bytes()
 {
+       if(unlikely(tls_total_ct_wq == 0))
+               return 0;
        return (unsigned)atomic_get(tls_total_ct_wq);
 }
 

_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to