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

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2021-04-16T09:56:11+02:00

core: usr avp - fix detection of invalid name and ids

- use the fields designated for str name or int id, code analyzers can
follow properly the execution path
- regression introduced in ca1821837dfe7dd6630f628d968ed4d1178c7040

---

Modified: src/core/usr_avp.c

---

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

---

diff --git a/src/core/usr_avp.c b/src/core/usr_avp.c
index e80e52d79d..8d8fa34603 100644
--- a/src/core/usr_avp.c
+++ b/src/core/usr_avp.c
@@ -148,16 +148,11 @@ avp_t *create_avp (avp_flags_t flags, avp_name_t name, 
avp_value_t val)
        struct str_str_data *ssd;
        int len;
 
-       if (name.s.s == NULL || name.s.len == 0) {
-               LM_ERR("0 ID or NULL NAME AVP!");
-               goto error;
-       }
-
        /* compute the required mem size */
        len = sizeof(struct usr_avp);
        if (flags&AVP_NAME_STR) {
                if ( name.s.s==0 || name.s.len==0) {
-                       LM_ERR("EMPTY NAME AVP!");
+                       LM_ERR("NULL or EMPTY NAME AVP!");
                        goto error;
                }
                if (flags&AVP_VAL_STR) {
@@ -168,8 +163,14 @@ avp_t *create_avp (avp_flags_t flags, avp_name_t name, 
avp_value_t val)
                        len += sizeof(struct str_int_data)-sizeof(union 
usr_avp_data)
                                + name.s.len + 1; /* Terminating zero for regex 
search */
                }
-       } else if (flags&AVP_VAL_STR) {
-               len += sizeof(str)-sizeof(union usr_avp_data) + val.s.len + 1;
+       } else {
+               if(name.n==0) {
+                       LM_ERR("0 ID AVP!");
+                       goto error;
+               }
+               if (flags&AVP_VAL_STR) {
+                       len += sizeof(str)-sizeof(union usr_avp_data) + 
val.s.len + 1;
+               }
        }
 
        avp = (struct usr_avp*)shm_malloc( len );


_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to