Browse code

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)
(cherry picked from commit 967dd294ba424bf66e27bebe4d6261e0c8a66471)

Daniel-Constantin Mierla authored on 16/04/2021 07:44:24 • Henning Westerholt committed on 22/10/2021 11:35:55
Showing 1 changed files
... ...
@@ -148,16 +148,11 @@ avp_t *create_avp (avp_flags_t flags, avp_name_t name, avp_value_t val)
148 148
 	struct str_str_data *ssd;
149 149
 	int len;
150 150
 
151
-	if (name.s.s == NULL || name.s.len == 0) {
152
-		LM_ERR("0 ID or NULL NAME AVP!");
153
-		goto error;
154
-	}
155
-
156 151
 	/* compute the required mem size */
157 152
 	len = sizeof(struct usr_avp);
158 153
 	if (flags&AVP_NAME_STR) {
159 154
 		if ( name.s.s==0 || name.s.len==0) {
160
-			LM_ERR("EMPTY NAME AVP!");
155
+			LM_ERR("NULL or EMPTY NAME AVP!");
161 156
 			goto error;
162 157
 		}
163 158
 		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)
168 163
 			len += sizeof(struct str_int_data)-sizeof(union usr_avp_data)
169 164
 				+ name.s.len + 1; /* Terminating zero for regex search */
170 165
 		}
171
-	} else if (flags&AVP_VAL_STR) {
172
-		len += sizeof(str)-sizeof(union usr_avp_data) + val.s.len + 1;
166
+	} else {
167
+		if(name.n==0) {
168
+			LM_ERR("0 ID AVP!");
169
+			goto error;
170
+		}
171
+		if (flags&AVP_VAL_STR) {
172
+			len += sizeof(str)-sizeof(union usr_avp_data) + val.s.len + 1;
173
+		}
173 174
 	}
174 175
 
175 176
 	avp = (struct usr_avp*)shm_malloc( len );