ソースを参照

lost: a few bug fixes reported from source code analyzer

Henning Westerholt 6 年 前
コミット
059b842639
1 ファイル変更36 行追加4 行削除
  1. 36 4
      src/modules/lost/utilities.c

+ 36 - 4
src/modules/lost/utilities.c

@@ -138,11 +138,14 @@ p_loc_t lost_new_loc(str rurn)
 
 
 	id = (char *)pkg_malloc(RANDSTRSIZE * sizeof(char) + 1);
 	id = (char *)pkg_malloc(RANDSTRSIZE * sizeof(char) + 1);
 	if(id == NULL) {
 	if(id == NULL) {
+		pkg_free(ptr);
 		goto err;
 		goto err;
 	}
 	}
 
 
 	urn = (char *)pkg_malloc(rurn.len + 1);
 	urn = (char *)pkg_malloc(rurn.len + 1);
 	if(urn == NULL) {
 	if(urn == NULL) {
+		pkg_free(ptr);
+		pkg_free(id);
 		goto err;
 		goto err;
 	}
 	}
 
 
@@ -179,6 +182,10 @@ char *lost_get_content(xmlNodePtr node, const char *name, int *lgth)
 
 
 	*lgth = 0;
 	*lgth = 0;
 	content = xmlNodeGetNodeContentByName(cur, name, NULL);
 	content = xmlNodeGetNodeContentByName(cur, name, NULL);
+	if (content == NULL) {
+		LM_ERR("could not get XML node content\n");
+		return cnt;
+	}
 	len = strlen(content);
 	len = strlen(content);
 
 
 	cnt = (char *)pkg_malloc((len + 1) * sizeof(char));
 	cnt = (char *)pkg_malloc((len + 1) * sizeof(char));
@@ -211,6 +218,10 @@ char *lost_get_property(xmlNodePtr node, const char *name, int *lgth)
 
 
 	*lgth = 0;
 	*lgth = 0;
 	content = xmlNodeGetAttrContentByName(cur, name);
 	content = xmlNodeGetAttrContentByName(cur, name);
+	if (content == NULL) {
+		LM_ERR("could not get XML node content\n");
+		return cnt;
+	}
 	len = strlen(content);
 	len = strlen(content);
 
 
 	cnt = (char *)pkg_malloc((len + 1) * sizeof(char));
 	cnt = (char *)pkg_malloc((len + 1) * sizeof(char));
@@ -275,7 +286,10 @@ char *lost_get_geolocation_header(struct sip_msg *msg, int *lgth)
 
 
 	*lgth = 0;
 	*lgth = 0;
 
 
-	parse_headers(msg, HDR_EOH_F, 0);
+	if(parse_headers(msg, HDR_EOH_F, 0) == -1) {
+		LM_ERR("failed to parse geolocation header\n");
+		return res;
+	}
 
 
 	for(hf = msg->headers; hf; hf = hf->next) {
 	for(hf = msg->headers; hf; hf = hf->next) {
 		if((hf->type == HDR_OTHER_T)
 		if((hf->type == HDR_OTHER_T)
@@ -318,7 +332,10 @@ char *lost_get_pai_header(struct sip_msg *msg, int *lgth)
 
 
 	*lgth = 0;
 	*lgth = 0;
 
 
-	parse_headers(msg, HDR_PAI_F, 0);
+	if (parse_headers(msg, HDR_PAI_F, 0) == -1) {
+		LM_ERR("could not parse PAI header\n");
+		return res;
+	}
 
 
 	for(hf = msg->headers; hf; hf = hf->next) {
 	for(hf = msg->headers; hf; hf = hf->next) {
 		if((hf->type == HDR_PAI_T)
 		if((hf->type == HDR_PAI_T)
@@ -360,7 +377,10 @@ char *lost_get_from_header(struct sip_msg *msg, int *lgth)
 
 
 	*lgth = 0;
 	*lgth = 0;
 
 
-	parse_headers(msg, HDR_FROM_F, 0);
+	if(parse_headers(msg, HDR_FROM_F, 0) == -1) {
+		LM_ERR("failed to parse From header\n");
+		return res;
+	}
 
 
 	if(msg->from == NULL || get_from(msg) == NULL) {
 	if(msg->from == NULL || get_from(msg) == NULL) {
 		LM_ERR("From header not found\n");
 		LM_ERR("From header not found\n");
@@ -469,6 +489,7 @@ https://tools.ietf.org/html/rfc6155
 	ptrLocationRequest = xmlNewNode(NULL, BAD_CAST "locationRequest");
 	ptrLocationRequest = xmlNewNode(NULL, BAD_CAST "locationRequest");
 	if(!ptrLocationRequest) {
 	if(!ptrLocationRequest) {
 		LM_ERR("locationRequest xmlNewNode() failed\n");
 		LM_ERR("locationRequest xmlNewNode() failed\n");
+		xmlFreeDoc(request);
 		return doc;
 		return doc;
 	}
 	}
 	xmlDocSetRootElement(request, ptrLocationRequest);
 	xmlDocSetRootElement(request, ptrLocationRequest);
@@ -485,6 +506,7 @@ https://tools.ietf.org/html/rfc6155
 	ptrDevice = xmlNewChild(ptrLocationRequest, NULL, BAD_CAST "device", NULL);
 	ptrDevice = xmlNewChild(ptrLocationRequest, NULL, BAD_CAST "device", NULL);
 	if(!ptrDevice) {
 	if(!ptrDevice) {
 		LM_ERR("locationRequest xmlNewChild() failed\n");
 		LM_ERR("locationRequest xmlNewChild() failed\n");
+		xmlFreeDoc(request);
 		return doc;
 		return doc;
 	}
 	}
 	/* properties */
 	/* properties */
@@ -497,12 +519,15 @@ https://tools.ietf.org/html/rfc6155
 	xmlDocDumpFormatMemory(request, &xmlbuff, &buffersize, 0);
 	xmlDocDumpFormatMemory(request, &xmlbuff, &buffersize, 0);
 	if(!xmlbuff) {
 	if(!xmlbuff) {
 		LM_ERR("locationRequest xmlDocDumpFormatMemory() failed\n");
 		LM_ERR("locationRequest xmlDocDumpFormatMemory() failed\n");
+		xmlFreeDoc(request);
 		return doc;
 		return doc;
 	}
 	}
 
 
 	doc = (char *)pkg_malloc((buffersize + 1) * sizeof(char));
 	doc = (char *)pkg_malloc((buffersize + 1) * sizeof(char));
 	if(doc == NULL) {
 	if(doc == NULL) {
 		LM_ERR("no more private memory\n");
 		LM_ERR("no more private memory\n");
+		xmlFree(xmlbuff);
+		xmlFreeDoc(request);
 		return doc;
 		return doc;
 	}
 	}
 
 
@@ -568,6 +593,7 @@ https://tools.ietf.org/html/rfc5222
 	ptrFindService = xmlNewNode(NULL, BAD_CAST "findService");
 	ptrFindService = xmlNewNode(NULL, BAD_CAST "findService");
 	if(!ptrFindService) {
 	if(!ptrFindService) {
 		LM_ERR("findService xmlNewNode() failed\n");
 		LM_ERR("findService xmlNewNode() failed\n");
+		xmlFreeDoc(request);
 		return doc;
 		return doc;
 	}
 	}
 	xmlDocSetRootElement(request, ptrFindService);
 	xmlDocSetRootElement(request, ptrFindService);
@@ -590,6 +616,7 @@ https://tools.ietf.org/html/rfc5222
 		ptrPoint = xmlNewChild(ptrLocation, NULL, BAD_CAST "Point", NULL);
 		ptrPoint = xmlNewChild(ptrLocation, NULL, BAD_CAST "Point", NULL);
 		if(!ptrPoint) {
 		if(!ptrPoint) {
 			LM_ERR("locationRequest xmlNewChild() failed\n");
 			LM_ERR("locationRequest xmlNewChild() failed\n");
+			xmlFreeDoc(request);
 			return doc;
 			return doc;
 		}
 		}
 		xmlNewProp(ptrPoint, BAD_CAST "xmlns",
 		xmlNewProp(ptrPoint, BAD_CAST "xmlns",
@@ -603,6 +630,7 @@ https://tools.ietf.org/html/rfc5222
 		ptrCircle = xmlNewChild(ptrLocation, NULL, BAD_CAST "gs:Circle", NULL);
 		ptrCircle = xmlNewChild(ptrLocation, NULL, BAD_CAST "gs:Circle", NULL);
 		if(!ptrCircle) {
 		if(!ptrCircle) {
 			LM_ERR("locationRequest xmlNewChild() failed\n");
 			LM_ERR("locationRequest xmlNewChild() failed\n");
+			xmlFreeDoc(request);
 			return doc;
 			return doc;
 		}
 		}
 		xmlNewProp(ptrCircle, BAD_CAST "xmlns:gml",
 		xmlNewProp(ptrCircle, BAD_CAST "xmlns:gml",
@@ -619,6 +647,7 @@ https://tools.ietf.org/html/rfc5222
 				ptrCircle, NULL, BAD_CAST "gs:radius", BAD_CAST buf);
 				ptrCircle, NULL, BAD_CAST "gs:radius", BAD_CAST buf);
 		if(!ptrRadius) {
 		if(!ptrRadius) {
 			LM_ERR("locationRequest xmlNewChild() failed\n");
 			LM_ERR("locationRequest xmlNewChild() failed\n");
+			xmlFreeDoc(request);
 			return doc;
 			return doc;
 		}
 		}
 		xmlNewProp(ptrRadius, BAD_CAST "uom",
 		xmlNewProp(ptrRadius, BAD_CAST "uom",
@@ -631,12 +660,15 @@ https://tools.ietf.org/html/rfc5222
 	xmlDocDumpFormatMemory(request, &xmlbuff, &buffersize, 0);
 	xmlDocDumpFormatMemory(request, &xmlbuff, &buffersize, 0);
 	if(!xmlbuff) {
 	if(!xmlbuff) {
 		LM_ERR("findService request xmlDocDumpFormatMemory() failed\n");
 		LM_ERR("findService request xmlDocDumpFormatMemory() failed\n");
+		xmlFreeDoc(request);
 		return doc;
 		return doc;
 	}
 	}
 
 
 	doc = (char *)pkg_malloc((buffersize + 1) * sizeof(char));
 	doc = (char *)pkg_malloc((buffersize + 1) * sizeof(char));
 	if(doc == NULL) {
 	if(doc == NULL) {
 		LM_ERR("no more private memory\n");
 		LM_ERR("no more private memory\n");
+		xmlFree(xmlbuff);
+		xmlFreeDoc(request);
 		return doc;
 		return doc;
 	}
 	}
 
 
@@ -650,4 +682,4 @@ https://tools.ietf.org/html/rfc5222
 	xmlFreeDoc(request);
 	xmlFreeDoc(request);
 
 
 	return doc;
 	return doc;
-}
+}