Browse code

app_perl: use local buffer to print dynamic string in pv_sprintf()

- avoid pkg malloc for temporary need
- fix leak in case of fmt parse error, discovered on a report by Dragos
Oancea

(cherry picked from commit 1c3e761fbd087ee578ce305d89f6b8ee4e9ab79d)

Daniel-Constantin Mierla authored on 30/09/2013 14:49:26
Showing 1 changed files
... ...
@@ -362,15 +362,11 @@ static inline int rewrite_ruri(struct sip_msg* _m, char* _s)
362 362
  */
363 363
 char *pv_sprintf(struct sip_msg *m, char *fmt) {
364 364
 	int buf_size = 4096;
365
+	char out[4096];
365 366
 	pv_elem_t *model;
366 367
 	str s;
367
-	char *out = (char *)pkg_malloc(buf_size);
368 368
 	char *ret = NULL;
369 369
 
370
-	if (!out) {
371
-		LM_ERR("pv_sprintf: Memory exhausted!\n");
372
-		return NULL;
373
-	}
374 370
 
375 371
 	s.s = fmt; s.len = strlen(s.s);
376 372
 	if(pv_parse_format(&s, &model) < 0) {
... ...
@@ -386,7 +382,6 @@ char *pv_sprintf(struct sip_msg *m, char *fmt) {
386 382
 	}
387 383
 
388 384
 	pv_elem_free_all(model);
389
-	pkg_free(out);
390 385
 
391 386
 	return ret;
392 387
 }