Browse code

core: free line_buf in case of error building via

- free buf in a very unlikely error converting src_ip to str in static
buffer
- coherent checking of msg pointer in the function

Daniel-Constantin Mierla authored on 21/04/2014 15:48:16
Showing 1 changed files
... ...
@@ -362,8 +362,10 @@ char* received_builder(struct sip_msg *msg, unsigned int *received_len)
362 362
 		return 0;
363 363
 	}
364 364
 	memcpy(buf, RECEIVED, RECEIVED_LEN);
365
-	if ( (tmp=ip_addr2a(source_ip))==0)
365
+	if ( (tmp=ip_addr2a(source_ip))==0) {
366
+		pkg_free(buf);
366 367
 		return 0; /* error*/
368
+	}
367 369
 	tmp_len=strlen(tmp);
368 370
 	len=RECEIVED_LEN+tmp_len;
369 371
 
... ...
@@ -2495,12 +2497,14 @@ char* via_builder( unsigned int *len,
2495 2495
                         con = tcpconn_get(send_info->id, 0, 0, 0, 0);
2496 2496
                 else {
2497 2497
                         LM_CRIT("BUG: via_builder called with null_id & to\n");
2498
+						pkg_free(line_buf);
2498 2499
                         return 0;
2499 2500
                 }
2500 2501
 
2501 2502
                 if (con == NULL) {
2502 2503
                         LM_WARN("TCP/TLS connection (id: %d) for WebSocket could not be found\n",
2503
-				send_info->id);
2504
+								send_info->id);
2505
+						pkg_free(line_buf);
2504 2506
                         return 0;
2505 2507
                 }
2506 2508
 
... ...
@@ -2511,6 +2515,7 @@ char* via_builder( unsigned int *len,
2511 2511
 		} else {
2512 2512
 			tcpconn_put(con);
2513 2513
 			LOG(L_CRIT, "BUG: via_builder: unknown proto %d\n", con->rcv.proto);
2514
+			pkg_free(line_buf);
2514 2515
 			return 0;
2515 2516
 		}
2516 2517
 		tcpconn_put(con);
... ...
@@ -2518,6 +2523,7 @@ char* via_builder( unsigned int *len,
2518 2518
 		memcpy(line_buf+MY_VIA_LEN-4, "WSS ", 4);
2519 2519
 	}else{
2520 2520
 		LOG(L_CRIT, "BUG: via_builder: unknown proto %d\n", send_info->proto);
2521
+		pkg_free(line_buf);
2521 2522
 		return 0;
2522 2523
 	}
2523 2524
 	/* add [] only if ipv6 and outbound socket address is used;
... ...
@@ -2620,7 +2626,7 @@ char* create_via_hf( unsigned int *len,
2620 2620
 #endif /* USE_TCP || USE_SCTP */
2621 2621
 
2622 2622
 	/* test and add rport parameter to local via - rfc3581 */
2623
-	if(msg->msg_flags&FL_ADD_LOCAL_RPORT) {
2623
+	if(msg && msg->msg_flags&FL_ADD_LOCAL_RPORT) {
2624 2624
 		/* params so far + ';rport' + '\0' */
2625 2625
 		via = (char*)pkg_malloc(extra_params.len+RPORT_LEN);
2626 2626
 		if(via==0) {