mirror of https://github.com/sipwise/kamailio.git
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
parent
616c716397
commit
b8535184c3
@ -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…
Reference in new issue