Module: kamailio Branch: 5.4 Commit: 967dd294ba424bf66e27bebe4d6261e0c8a66471 URL: https://github.com/kamailio/kamailio/commit/967dd294ba424bf66e27bebe4d6261e0...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2021-04-16T09:58:16+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
(cherry picked from commit e4506385ca5a56d4861f36e85c1049599cba398f)
---
Modified: src/core/usr_avp.c
---
Diff: https://github.com/kamailio/kamailio/commit/967dd294ba424bf66e27bebe4d6261e0... Patch: https://github.com/kamailio/kamailio/commit/967dd294ba424bf66e27bebe4d6261e0...
---
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 );