Browse code

xprint: safety checks for error cases

Daniel-Constantin Mierla authored on 20/07/2017 07:28:58
Showing 1 changed files
... ...
@@ -814,7 +814,10 @@ static int xl_get_header(struct sip_msg *msg, str *res, str *hp, int hi, int hf)
814 814
 	p = local_buf;
815 815
 
816 816
 	/* we need to be sure we have parsed all headers */
817
-	parse_headers(msg, HDR_EOH_F, 0);
817
+	if(parse_headers(msg, HDR_EOH_F, 0)<0) {
818
+		LM_ERR("failed to parse headers\n");
819
+		return xl_get_null(msg, res, hp, hi, hf);
820
+	}
818 821
 	for (hdrf=msg->headers; hdrf; hdrf=hdrf->next)
819 822
 	{
820 823
 		if(hp->s==NULL)
... ...
@@ -1898,9 +1901,10 @@ int xl_mod_init()
1898 1901
 					if (inet_ntop(he->h_addrtype, he->h_addr_list[i], s, HOSTNAME_MAX)) {
1899 1902
 						if (str_ipaddr.len==0) {
1900 1903
 							str_ipaddr.len=strlen(s);
1901
-							str_ipaddr.s=(char*)pkg_malloc(str_ipaddr.len);
1904
+							str_ipaddr.s=(char*)pkg_malloc(str_ipaddr.len+1);
1902 1905
 							if (str_ipaddr.s) {
1903 1906
 								memcpy(str_ipaddr.s, s, str_ipaddr.len);
1907
+								str_ipaddr.s[str_ipaddr.len] = '\0';
1904 1908
 							} else {
1905 1909
 								str_ipaddr.len=0;
1906 1910
 								LOG(L_ERR, "ERROR: xl_mod_init: No memory left for str_ipaddr\n");