Browse code

core: kemi - use parse_hname2_str() to avoid cloning header name

Daniel-Constantin Mierla authored on 23/10/2020 07:28:14
Showing 1 changed files
... ...
@@ -2275,8 +2275,6 @@ static int sr_kemi_hdr_append_to_reply(sip_msg_t *msg, str *txt)
2275 2275
 static sr_kemi_xval_t* sr_kemi_hdr_get_mode(sip_msg_t *msg, str *hname, int idx,
2276 2276
 		int rmode)
2277 2277
 {
2278
-	char hbuf[256];
2279
-	str s;
2280 2278
 	hdr_field_t shdr;
2281 2279
 	hdr_field_t *ihdr;
2282 2280
 #define SR_KEMI_VHDR_SIZE 256
... ...
@@ -2296,23 +2294,12 @@ static sr_kemi_xval_t* sr_kemi_hdr_get_mode(sip_msg_t *msg, str *hname, int idx,
2296 2294
 		sr_kemi_xval_null(&_sr_kemi_xval, rmode);
2297 2295
 		return &_sr_kemi_xval;
2298 2296
 	}
2299
-	if(hname->len>=252) {
2300
-		LM_ERR("header name too long\n");
2297
+	if (parse_hname2_str(hname, &shdr)==0) {
2298
+		LM_ERR("error parsing header name [%.*s]\n", hname->len, hname->s);
2301 2299
 		sr_kemi_xval_null(&_sr_kemi_xval, rmode);
2302 2300
 		return &_sr_kemi_xval;
2303 2301
 	}
2304 2302
 
2305
-	memcpy(hbuf, hname->s, hname->len);
2306
-	hbuf[hname->len] = ':';
2307
-	hbuf[hname->len+1] = '\0';
2308
-	s.s = hbuf;
2309
-	s.len = hname->len + 1;
2310
-
2311
-	if (parse_hname2_short(s.s, s.s + s.len, &shdr)==0) {
2312
-		LM_ERR("error parsing header name [%.*s]\n", s.len, s.s);
2313
-		sr_kemi_xval_null(&_sr_kemi_xval, rmode);
2314
-		return &_sr_kemi_xval;
2315
-	}
2316 2303
 	n = 0;
2317 2304
 	for (ihdr=msg->headers; ihdr; ihdr=ihdr->next) {
2318 2305
 		hmatch = 0;