MT#63826 db_redis: revert support of NULL values

db_redis module implicitly supports conversion
of <null> key values into empty "" strings.

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

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

Additionally: introduce the memcpy() guard.

Change-Id: I96515b8a4dfea6eef16a05b5d9f970946a9fc915
(cherry picked from commit 743265a8c4)
mr14.0
Donat Zenichev 4 months ago
parent 616c716397
commit b8535184c3

@ -46,6 +46,8 @@ sipwise/presence_offline_cleanup.patch
sipwise/permissions-don-t-allow-reloads-in-the-middle-of-ong.patch
sipwise/dlg_get_var_error_more_verbose_on_dlg
sipwise/db_redis_protect_length_overflow.patch
sipwise/db_redis_support_null_key_values.patch
### Don't just put stuff in any order
### use gbp pq import/export tooling to help maintain patches
###

@ -0,0 +1,31 @@
--- a/src/modules/db_redis/redis_table.c
+++ b/src/modules/db_redis/redis_table.c
@@ -32,11 +32,6 @@ int db_redis_key_add_string(redis_key_t
{
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",
db_redis_max_key_len, len);
@@ -56,8 +51,14 @@ int db_redis_key_add_string(redis_key_t
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) {
Loading…
Cancel
Save