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

Author: Donat Zenichev <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2026-01-21T10:30:38+01:00

db_redis: revert support of NULL values

db_redis module implicitly supports conversion
of <null> key values into empty "" strings,
see: `db_redis_val2str()`.

Remove empty-string/zero-length guards introduced
previously, because they break this support.

E.g.: dialog and usrloc modules can in fact
handle <null> key values.

Additionally: introduce the memcpy() guard,
because running it on the NULL pointer / 0 length
is in fact technically a typical UB.

This wasn't noticed before, because modern
libc implementations do not dereference pointers
when the size is zero.

---

Modified: src/modules/db_redis/redis_table.c

---

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

---

diff --git a/src/modules/db_redis/redis_table.c 
b/src/modules/db_redis/redis_table.c
index 0b67c107590..32f0694def3 100644
--- a/src/modules/db_redis/redis_table.c
+++ b/src/modules/db_redis/redis_table.c
@@ -34,11 +34,6 @@ int db_redis_key_add_string(redis_key_t **list, const char 
*entry, size_t len)
 {
        redis_key_t *k;
 
-       if(!entry || !len) {
-               LM_ERR("Empty entry or zero length\n");
-               return -1;
-       }
-
        if(db_redis_max_key_len > 0 && len > db_redis_max_key_len) {
                LM_ERR("Too big length for key being added: allowed '%u' / 
given "
                           "'%zu'\n",
@@ -59,8 +54,14 @@ int db_redis_key_add_string(redis_key_t **list, const char 
*entry, size_t len)
                goto err;
        }
 
-       memcpy(k->key.s, entry, len);
-       k->key.s[len] = '\0';
+       /* run memcpy only on non-NULL pointer, because in fact it may happen
+        * it comes here empty and with len = 0, this is then an implicit
+        * conversion of <null> redis key value into the empty "" string.
+        * see `db_redis_val2str()`
+        * This is the allowed behavior, but avoid then running memcpy() on it. 
*/
+       if(entry && len > 0)
+               memcpy(k->key.s, entry, len);
+       k->key.s[len] = '\0'; /* at least 1 byte is already pre-allocated 
before */
        k->key.len = len;
 
        if(!*list) {

_______________________________________________
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