Browse code

- stronger checks for params in avp function (reported by Juha Heinanen <jh@tutpro.com>)

Bogdan-Andrei Iancu authored on 01/06/2005 09:30:17
Showing 1 changed files
... ...
@@ -98,9 +98,18 @@ int add_avp(unsigned short flags, int_str name, int_str val)
98 98
 
99 99
 	assert( crt_avps!=0 );
100 100
 
101
+	if ( name.s==0 ) {
102
+		LOG(L_ERR,"ERROR:avp:add_avp: 0 ID or NULL NAME AVP!");
103
+		goto error;
104
+	}
105
+
101 106
 	/* compute the required mem size */
102 107
 	len = sizeof(struct usr_avp);
103 108
 	if (flags&AVP_NAME_STR) {
109
+		if ( name.s->s==0 || name.s->len==0) {
110
+			LOG(L_ERR,"ERROR:avp:add_avp: EMPTY NAME AVP!");
111
+			goto error;
112
+		}
104 113
 		if (flags&AVP_VAL_STR)
105 114
 			len += sizeof(struct str_str_data)-sizeof(void*) + name.s->len
106 115
 				+ (val.s->len+1);
... ...
@@ -263,11 +272,21 @@ struct usr_avp *search_first_avp( unsigned short name_type,
263 263
 	if (*crt_avps==0)
264 264
 		return 0;
265 265
 
266
+	if ( name.s==0) {
267
+		LOG(L_ERR,"ERROR:avp:search_first_avp: 0 ID or NULL NAME AVP!");
268
+		return 0;
269
+	}
270
+
266 271
 	/* search for the AVP by ID (&name) */
267
-	if (name_type&AVP_NAME_STR)
272
+	if (name_type&AVP_NAME_STR) {
273
+		if ( name.s->s==0 || name.s->len==0) {
274
+			LOG(L_ERR,"ERROR:avp:search_first_avp: EMPTY NAME AVP!");
275
+			return 0;
276
+		}
268 277
 		avp = internal_search_name_avp(*crt_avps,compute_ID(name.s),name.s);
269
-	else
278
+	} else {
270 279
 		avp = internal_search_ID_avp( *crt_avps, name.n );
280
+	}
271 281
 
272 282
 	/* get the value - if required */
273 283
 	if (avp && val)