Bladeren bron

lost: fixed defects reported from Coverity Scan

- in lost_function(): illegal access
- in lost_held_type(): null pointer dereferences
- in lost_xpath_location(): resource leak, control flow,
  null pointer dereferences
- besides: README update and code refactoring.
Wolfgang Kampichler 5 jaren geleden
bovenliggende
commit
340bb1efbf
4 gewijzigde bestanden met toevoegingen van 118 en 104 verwijderingen
  1. 2 0
      src/modules/lost/doc/lost_admin.xml
  2. 44 64
      src/modules/lost/functions.c
  3. 71 39
      src/modules/lost/utilities.c
  4. 1 1
      src/modules/lost/utilities.h

+ 2 - 0
src/modules/lost/doc/lost_admin.xml

@@ -201,6 +201,8 @@
 						<emphasis>url</emphasis> - the location reference returned
                         in the HELD locationRequest response - this reference may be
                         added as Geolocation header value and forwarded downstream
+                        Note: to work properly, it is required to include "locationURI"
+                        in the location_type parameter.
                     </para></listitem>
                     <listitem><para>
 						<emphasis>error</emphasis> - any error code returned in the

+ 44 - 64
src/modules/lost/functions.c

@@ -83,10 +83,7 @@ char *lost_held_type(char *type, int *exact, int *lgth)
 	if(strstr(type, HELD_TYPE_ANY)) {
 		len = strlen(ret) + strlen(HELD_TYPE_ANY) + 1;
 		tmp = pkg_realloc(ret, len);
-		if(!tmp) {
-			LM_ERR("no more private memory\n");
-			goto err;
-		}
+		if(tmp == NULL) goto err;
 		ret = tmp;
 		strcat(ret, HELD_TYPE_ANY);
 		*exact = 0;
@@ -94,10 +91,7 @@ char *lost_held_type(char *type, int *exact, int *lgth)
 		if(strstr(type, HELD_TYPE_CIV)) {
 			len = strlen(ret) + strlen(HELD_TYPE_CIV) + 1;
 			tmp = pkg_realloc(ret, len);
-			if(tmp == NULL) {
-				LM_ERR("no more private memory\n");
-				goto err;
-			}
+			if(tmp == NULL) goto err;
 			ret = tmp;
 			strcat(ret, HELD_TYPE_CIV);
 		}
@@ -105,19 +99,13 @@ char *lost_held_type(char *type, int *exact, int *lgth)
 			if(strlen(ret) > 1) {
 				len = strlen(ret) + strlen(HELD_TYPE_SEP) + 1;
 				tmp = pkg_realloc(ret, len);
-				if(tmp == NULL) {
-					LM_ERR("no more private memory\n");
-					goto err;
-				}
+				if(tmp == NULL) goto err;
 				ret = tmp;
 				strcat(ret, HELD_TYPE_SEP);
 			}
 			len = strlen(ret) + strlen(HELD_TYPE_GEO) + 1;
 			tmp = pkg_realloc(ret, len);
-			if(tmp == NULL) {
-				LM_ERR("no more private memory\n");
-				goto err;
-			}
+			if(tmp == NULL) goto err;
 			ret = tmp;
 			strcat(ret, HELD_TYPE_GEO);
 		}
@@ -125,19 +113,13 @@ char *lost_held_type(char *type, int *exact, int *lgth)
 			if(strlen(ret) > 1) {
 				len = strlen(ret) + strlen(HELD_TYPE_SEP) + 1;
 				tmp = pkg_realloc(ret, len);
-				if(tmp == NULL) {
-					LM_ERR("no more private memory\n");
-					goto err;
-				}
+				if(tmp == NULL) goto err;
 				ret = tmp;
 				strcat(ret, HELD_TYPE_SEP);
 			}
 			len = strlen(ret) + strlen(HELD_TYPE_URI) + 1;
 			tmp = pkg_realloc(ret, len);
-			if(tmp == NULL) {
-				LM_ERR("no more private memory\n");
-				goto err;
-			}
+			if(tmp == NULL) goto err;
 			ret = tmp;
 			strcat(ret, HELD_TYPE_URI);
 		}
@@ -147,7 +129,8 @@ char *lost_held_type(char *type, int *exact, int *lgth)
 	return ret;
 
 err:
-	if(ret) {
+	LM_ERR("no more private memory\n");
+	if (ret != NULL) {
 		pkg_free(ret);
 	}
 	*lgth = 0;
@@ -208,7 +191,7 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 			LM_ERR("cannot get device id\n");
 			goto err;
 		}
-		if(!did.s) {
+		if(did.len == 0) {
 			LM_ERR("no device id found\n");
 			goto err;
 		}
@@ -245,7 +228,7 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 	/* assemble locationRequest */
 	held = lost_new_held(did, rtype, held_resp_time, held_exact_type);
 
-	if(!held) {
+	if(held == NULL) {
 		LM_ERR("held object allocation failed\n");
 		lost_free_string(&idhdr);
 		goto err;
@@ -253,10 +236,10 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 	que.s = lost_held_location_request(held, &que.len);
 
 	/* free memory */
-	lost_free_held(held);
-	lost_free_string(&idhdr);
 	did.s = NULL;
 	did.len = 0;
+	lost_free_held(held);
+	lost_free_string(&idhdr);
 
 	if(que.len == 0) {
 		LM_ERR("held request document error\n");
@@ -271,8 +254,7 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 	/* only HTTP 2xx responses are accepted */
 	if(curlres >= 300 || curlres < 100) {
 		LM_ERR("[%.*s] failed with error: %d\n", con.len, con.s, curlres);
-		res.s = NULL;
-		res.len = 0;
+		lost_free_string(&res);
 		goto err;
 	}
 
@@ -283,10 +265,10 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 	/* read and parse the returned xml */
 	doc = xmlReadMemory(res.s, res.len, 0, NULL,
 			XML_PARSE_NOBLANKS | XML_PARSE_NONET | XML_PARSE_NOCDATA);
-	if(!doc) {
+	if(doc == NULL) {
 		LM_WARN("invalid xml document: [%.*s]\n", res.len, res.s);
 		doc = xmlRecoverMemory(res.s, res.len);
-		if(!doc) {
+		if(doc == NULL) {
 			LM_ERR("xml document recovery failed on: [%.*s]\n", res.len, res.s);
 			goto err;
 		}
@@ -294,19 +276,19 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 		LM_DBG("xml document recovered\n");
 	}
 	root = xmlDocGetRootElement(doc);
-	if(!root) {
+	if(root == NULL) {
 		LM_ERR("empty xml document\n");
 		goto err;
 	}
 	/* check the root element ... shall be locationResponse, or errors */
-	if(!xmlStrcmp(root->name, (const xmlChar *)"locationResponse")) {
+	if(xmlStrcmp(root->name, (const xmlChar *)"locationResponse") == 0) {
 
 		LM_DBG("HELD location response [%.*s]\n", res.len, res.s);
 
 		for(cur_node = root->children; cur_node; cur_node = cur_node->next) {
 			if(cur_node->type == XML_ELEMENT_NODE) {
-				if(!xmlStrcmp(
-						   cur_node->name, (const xmlChar *)"locationUriSet")) {
+				if(xmlStrcmp(cur_node->name,
+							(const xmlChar *)"locationUriSet") == 0) {
 
 					LM_DBG("*** node '%s' found\n", cur_node->name);
 
@@ -318,11 +300,12 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 						geo.s = NULL;
 					}
 				}
-				if(!xmlStrcmp(cur_node->name, (const xmlChar *)"presence")) {
+				if(xmlStrcmp(cur_node->name,
+							(const xmlChar *)"presence") == 0) {
 
 					LM_DBG("*** node '%s' found\n", cur_node->name);
 
-					/* respnse contains presence node */
+					/* response contains presence node */
 					presence = 1;
 				}
 			}
@@ -341,8 +324,7 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 			if(curlres >= 300 || curlres < 100) {
 				LM_ERR("dereferencing location failed: %d\n", curlres);
 				/* free memory */
-				pidfuri.s = NULL;
-				pidfuri.len = 0;
+				lost_free_string(&pidfuri);
 				goto err;
 			}
 
@@ -360,13 +342,13 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 				res.len = pidfuri.len;
 			}
 		}
-	} else if(!xmlStrcmp(root->name, (const xmlChar *)"error")) {
+	} else if(xmlStrcmp(root->name, (const xmlChar *)"error") == 0) {
 
 		LM_DBG("HELD error response [%.*s]\n", res.len, res.s);
 
 		/* get the error patterm */
 		err.s = lost_get_property(root, (char *)"code", &err.len);
-		if(!err.s) {
+		if(err.len == 0) {
 			LM_ERR("error - code property not found: [%.*s]\n", res.len, res.s);
 			goto err;
 		}
@@ -406,8 +388,9 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 	return (err.len > 0) ? LOST_SERVER_ERROR : LOST_SUCCESS;
 
 err:
-	if(doc)
+	if(doc != NULL) {
 		xmlFreeDoc(doc);
+	}
 
 	return LOST_CLIENT_ERROR;
 }
@@ -570,8 +553,7 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 					if(curlres >= 300 || curlres < 100) {
 						LM_ERR("http GET failed with error: %d\n", curlres);
 						/* free memory */
-						pidfhdr.s = NULL;
-						pidfhdr.len = 0;
+						lost_free_string(&pidfhdr);
 						goto err;
 					}
 
@@ -579,8 +561,6 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 
 					if(pidfhdr.len == 0) {
 						LM_ERR("dereferencing location failed\n");
-						/* free memory */
-
 						goto err;
 					}
 					pidf.s = pidfhdr.s;
@@ -605,10 +585,10 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 	doc = xmlReadMemory(pidf.s, pidf.len, 0, NULL,
 			XML_PARSE_NOBLANKS | XML_PARSE_NONET | XML_PARSE_NOCDATA);
 
-	if(!doc) {
+	if(doc == NULL) {
 		LM_WARN("invalid xml (pidf-lo): [%.*s]\n", pidf.len, pidf.s);
 		doc = xmlRecoverMemory(pidf.s, pidf.len);
-		if(!doc) {
+		if(doc == NULL) {
 			LM_ERR("xml (pidf-lo) recovery failed on: [%.*s]\n", pidf.len,
 					pidf.s);
 			goto err;
@@ -618,7 +598,7 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 	}
 
 	root = xmlDocGetRootElement(doc);
-	if(!root) {
+	if(root == NULL) {
 		LM_ERR("empty pidf-lo document\n");
 		goto err;
 	}
@@ -626,7 +606,7 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 			|| (!xmlStrcmp(root->name, (const xmlChar *)"locationResponse"))) {
 		/* get the geolocation: point or circle, urn, ... */
 		loc = lost_new_loc(urn);
-		if(!loc) {
+		if(loc == NULL) {
 			LM_ERR("location object allocation failed\n");
 			goto err;
 		}
@@ -642,9 +622,9 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 	}
 
 	/* free memory */
-	lost_free_string(&pidfhdr);
 	pidf.s = NULL;
 	pidf.len = 0;
+	lost_free_string(&pidfhdr);
 
 	/* check if connection exits */
 	if(httpapi.http_connection_exists(&con) == 0) {
@@ -654,9 +634,8 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 	/* assemble findService request */
 	res.s = lost_find_service_request(loc, &res.len);
 	/* free memory */
-	if(loc)
-		lost_free_loc(loc);
-
+	lost_free_loc(loc);
+	loc = NULL;
 	xmlFreeDoc(doc);
 	doc = NULL;
 
@@ -672,8 +651,7 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 	/* only HTTP 2xx responses are accepted */
 	if(curlres >= 300 || curlres < 100) {
 		LM_ERR("[%.*s] failed with error: %d\n", con.len, con.s, curlres);
-		ret.s = NULL;
-		ret.len = 0;
+		lost_free_string(&ret);
 		goto err;
 	}
 
@@ -682,7 +660,7 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 	/* free memory */
 	lost_free_string(&res);
 
-	if(!ret.s) {
+	if(ret.len == 0) {
 		LM_ERR("findService request failed\n");
 		goto err;
 	}
@@ -693,10 +671,10 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 	doc = xmlReadMemory(ret.s, ret.len, 0, 0,
 			XML_PARSE_NOBLANKS | XML_PARSE_NONET | XML_PARSE_NOCDATA);
 
-	if(!doc) {
+	if(doc == NULL) {
 		LM_ERR("invalid xml document: [%.*s]\n", ret.len, ret.s);
 		doc = xmlRecoverMemory(ret.s, ret.len);
-		if(!doc) {
+		if(doc == NULL) {
 			LM_ERR("xml document recovery failed on: [%.*s]\n", ret.len, ret.s);
 			goto err;
 		}
@@ -704,7 +682,7 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 		LM_DBG("xml document recovered\n");
 	}
 	root = xmlDocGetRootElement(doc);
-	if(!root) {
+	if(root == NULL) {
 		LM_ERR("empty xml document: [%.*s]\n", ret.len, ret.s);
 		/* free memory */
 		lost_free_string(&ret);
@@ -784,10 +762,12 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 	return (err.len > 0) ? LOST_SERVER_ERROR : LOST_SUCCESS;
 
 err:
-	if(loc)
+	if(loc != NULL) {
 		lost_free_loc(loc);
-	if(doc)
+	}
+	if(doc != NULL) {
 		xmlFreeDoc(doc);
+	}
 
 	return LOST_CLIENT_ERROR;
 }

+ 71 - 39
src/modules/lost/utilities.c

@@ -131,7 +131,7 @@ p_loc_t lost_new_loc(str rurn)
 	ptr->longitude = NULL;
 	ptr->latitude = NULL;
 	ptr->geodetic = NULL;
-	ptr->civic = NULL;
+	ptr->xpath = NULL;
 	ptr->profile = NULL;
 	ptr->radius = 0;
 	ptr->recursive = LOST_RECURSION_TRUE; /* set recursion to true */
@@ -201,8 +201,8 @@ void lost_free_loc(p_loc_t ptr)
 {
 	pkg_free(ptr->identity);
 	pkg_free(ptr->urn);
-	if(ptr->civic)
-		pkg_free(ptr->civic);
+	if(ptr->xpath)
+		pkg_free(ptr->xpath);
 	if(ptr->geodetic)
 		pkg_free(ptr->geodetic);
 	if(ptr->longitude)
@@ -607,6 +607,7 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_loc_t loc)
 	const unsigned char s_civic[] = LOST_CIV;
 
 	char *ptr = NULL;
+	char *tmp = NULL;
 	char *s_profile = NULL;
 
 	int buffersize = 0;
@@ -626,14 +627,23 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_loc_t loc)
 	}
 
 	nodes = result->nodesetval;
-	if(nodes) {
-		size = (nodes) ? nodes->nodeNr : 0;
+	if(nodes != NULL) {
+		size = nodes->nodeNr;
 		for(i = 0; i < size; ++i) {
+			if(nodes->nodeTab[i] == NULL) {
+				LM_WARN("xpath '%s' failed\n", xpath);
+				xmlXPathFreeObject(result);
+				return -1;
+			}
 			if(nodes->nodeTab[i]->type == XML_ELEMENT_NODE) {
 				cur = nodes->nodeTab[i];
 				/* check if child element is point, circle or civic */
 				while(nok < LOST_XPATH_DPTH) {
-					if(cur->children) {
+					if(cur->children == NULL) {
+						/* no additional DOM level */
+						break;
+					} else {
+						/* check current DOM level */
 						nok++;
 						cname = BAD_CAST cur->name;
 						if(xmlStrcasecmp(cname, s_point) == 0) {
@@ -648,49 +658,49 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_loc_t loc)
 							s_profile = LOST_PRO_CIVIC;
 							break;
 						}
+						/* nothing found ... try next DOM level */
+						cur = cur->children;
 					}
-					/* nothing found ... try next DOM level */
-					cur = cur->children;
 				}
 
 				if(nok == 0) {
 					LM_DBG("xpath '%s' returned valid element (level %d/%d)\n",
-							xpath, nok, LOST_XPATH_DPTH - 1);
+							xpath, nok, LOST_XPATH_DPTH);
 				} else if(nok < LOST_XPATH_DPTH) {
 					/* malformed pidf-lo but still ok */
 					LM_WARN("xpath '%s' returned malformed pidf-lo (level "
 							"%d/%d)\n",
-							xpath, nok, LOST_XPATH_DPTH - 1);
+							xpath, nok, LOST_XPATH_DPTH);
 				} else {
 					/* really bad pidf-lo */
 					LM_WARN("xpath '%s' failed (level %d/%d)\n", xpath, nok,
-							LOST_XPATH_DPTH - 1);
+							LOST_XPATH_DPTH);
 					xmlXPathFreeObject(result);
 					return -1;
 				}
-				nok = -1;
 
-				if(!cur) {
+				if(cur == NULL) {
 					LM_ERR("xpath xmlCopyNode() failed\n");
 					xmlXPathFreeObject(result);
 					return -1;
 				}
 
 				root = xmlCopyNode(cur, 1);
-				if(!root) {
+				if(root == NULL) {
 					LM_ERR("xpath xmlCopyNode() failed\n");
 					xmlXPathFreeObject(result);
 					return -1;
 				}
+
 				new = xmlNewDoc(BAD_CAST "1.0");
-				if(!new) {
+				if(new == NULL) {
 					LM_ERR("xpath xmlNewDoc() failed\n");
 					xmlXPathFreeObject(result);
 					return -1;
 				}
 				xmlDocSetRootElement(new, root);
 				xmlDocDumpFormatMemory(new, &xmlbuff, &buffersize, 0);
-				if(!xmlbuff) {
+				if(xmlbuff == NULL) {
 					LM_ERR("xpath xmlDocDumpFormatMemory() failed\n");
 					xmlFreeDoc(new);
 					xmlXPathFreeObject(result);
@@ -698,19 +708,22 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_loc_t loc)
 				}
 				/* take the first location-info element only */
 				if(i == 0) {
-					remove = strlen("<?xml version='1.0'?>\n");
-					buffersize = buffersize - remove;
-					ptr = (char *)pkg_malloc((buffersize + 1) * sizeof(char));
-					if(ptr == NULL) {
+					/* return the current profile */
+					loc->profile = (char *)pkg_malloc(strlen(s_profile) + 1);
+					if(loc->profile == NULL) {
 						xmlFree(xmlbuff);
 						xmlFreeDoc(new);
 						xmlXPathFreeObject(result);
 						goto err;
 					}
+					memset(loc->profile, 0, strlen(s_profile) + 1);
+					memcpy(loc->profile, s_profile, strlen(s_profile));
 
-					loc->profile = (char *)pkg_malloc(strlen(s_profile) + 1);
-					if(loc->profile == NULL) {
-						pkg_free(ptr);
+					/* remove xml header from location element */
+					remove = strlen("<?xml version='1.0'?>\n");
+					buffersize = buffersize - remove;
+					ptr = (char *)pkg_malloc((buffersize + 1) * sizeof(char));
+					if(ptr == NULL) {
 						xmlFree(xmlbuff);
 						xmlFreeDoc(new);
 						xmlXPathFreeObject(result);
@@ -720,10 +733,25 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_loc_t loc)
 					memset(ptr, 0, buffersize);
 					memcpy(ptr, (char *)(xmlbuff + remove), buffersize);
 					ptr[buffersize] = '\0';
-					loc->civic = lost_trim_content(ptr, &len);
+					
+					/* trim the result */
+					tmp = lost_trim_content(ptr, &len);
 
-					memset(loc->profile, 0, strlen(s_profile) + 1);
-					memcpy(loc->profile, (char *)s_profile, strlen(s_profile));
+					/* return the location DOM */
+					loc->xpath = (char *)pkg_malloc(len + 1);
+					if(loc->xpath == NULL) {
+						pkg_free(ptr);
+						ptr = NULL;
+						xmlFree(xmlbuff);
+						xmlFreeDoc(new);
+						xmlXPathFreeObject(result);
+						goto err;
+					}
+					memset(loc->xpath, 0, len + 1);
+					memcpy(loc->xpath, tmp, len);
+					/* free memory */
+					pkg_free(ptr);
+					ptr = NULL;
 				} else {
 					LM_WARN("xpath location-info element(%d) ignored\n", i + 1);
 				}
@@ -731,6 +759,10 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_loc_t loc)
 				xmlFreeDoc(new);
 			}
 		}
+	} else {
+		LM_WARN("xpath '%s' failed\n", xpath);
+		xmlXPathFreeObject(result);
+		return -1;
 	}
 	xmlXPathFreeObject(result);
 
@@ -797,13 +829,13 @@ https://tools.ietf.org/html/rfc5985
 
 	/* create request */
 	request = xmlNewDoc(BAD_CAST "1.0");
-	if(!request) {
+	if(request == NULL) {
 		LM_ERR("locationRequest xmlNewDoc() failed\n");
 		return doc;
 	}
 	/* locationRequest - element */
 	ptrLocationRequest = xmlNewNode(NULL, BAD_CAST "locationRequest");
-	if(!ptrLocationRequest) {
+	if(ptrLocationRequest == NULL) {
 		LM_ERR("locationRequest xmlNewNode() failed\n");
 		xmlFreeDoc(request);
 		return doc;
@@ -826,7 +858,7 @@ https://tools.ietf.org/html/rfc5985
 											 : BAD_CAST "false");
 	/* device - element */
 	ptrDevice = xmlNewChild(ptrLocationRequest, NULL, BAD_CAST "device", NULL);
-	if(!ptrDevice) {
+	if(ptrDevice == NULL) {
 		LM_ERR("locationRequest xmlNewChild() failed\n");
 		xmlFreeDoc(request);
 		return doc;
@@ -838,7 +870,7 @@ https://tools.ietf.org/html/rfc5985
 	xmlNewChild(ptrDevice, NULL, BAD_CAST "uri", BAD_CAST held->identity);
 
 	xmlDocDumpFormatMemory(request, &xmlbuff, &buffersize, 0);
-	if(!xmlbuff) {
+	if(xmlbuff == NULL) {
 		LM_ERR("locationRequest xmlDocDumpFormatMemory() failed\n");
 		xmlFreeDoc(request);
 		return doc;
@@ -908,13 +940,13 @@ https://tools.ietf.org/html/rfc5222
  */
 	/* create request */
 	request = xmlNewDoc(BAD_CAST "1.0");
-	if(!request) {
+	if(request == NULL) {
 		LM_ERR("findService request xmlNewDoc() failed\n");
 		return doc;
 	}
 	/* findService - element */
 	ptrFindService = xmlNewNode(NULL, BAD_CAST "findService");
-	if(!ptrFindService) {
+	if(ptrFindService == NULL) {
 		LM_ERR("findService xmlNewNode() failed\n");
 		xmlFreeDoc(request);
 		return doc;
@@ -936,10 +968,10 @@ https://tools.ietf.org/html/rfc5222
 	/* set pos */
 	snprintf(buf, BUFSIZE, "%s %s", loc->latitude, loc->longitude);
 	/* xpath result */
-	if(loc->civic) {
+	if(loc->xpath != NULL) {
 		xmlParseInNodeContext(
-				ptrLocation, loc->civic, strlen(loc->civic), 0, &ptrNode);
-		if(!ptrNode) {
+				ptrLocation, loc->xpath, strlen(loc->xpath), 0, &ptrNode);
+		if(ptrNode == NULL) {
 			LM_ERR("locationRequest xmlParseInNodeContext() failed\n");
 			xmlFreeDoc(request);
 			return doc;
@@ -950,7 +982,7 @@ https://tools.ietf.org/html/rfc5222
 	/* Point */
 	else if(loc->radius == 0) {
 		ptrPoint = xmlNewChild(ptrLocation, NULL, BAD_CAST "Point", NULL);
-		if(!ptrPoint) {
+		if(ptrPoint == NULL) {
 			LM_ERR("locationRequest xmlNewChild() failed\n");
 			xmlFreeDoc(request);
 			return doc;
@@ -965,7 +997,7 @@ https://tools.ietf.org/html/rfc5222
 	/* circle - Point */
 	else {
 		ptrCircle = xmlNewChild(ptrLocation, NULL, BAD_CAST "gs:Circle", NULL);
-		if(!ptrCircle) {
+		if(ptrCircle == NULL) {
 			LM_ERR("locationRequest xmlNewChild() failed\n");
 			xmlFreeDoc(request);
 			return doc;
@@ -982,7 +1014,7 @@ https://tools.ietf.org/html/rfc5222
 		snprintf(buf, BUFSIZE, "%d", loc->radius);
 		ptrRadius = xmlNewChild(
 				ptrCircle, NULL, BAD_CAST "gs:radius", BAD_CAST buf);
-		if(!ptrRadius) {
+		if(ptrRadius == NULL) {
 			LM_ERR("locationRequest xmlNewChild() failed\n");
 			xmlFreeDoc(request);
 			return doc;
@@ -995,7 +1027,7 @@ https://tools.ietf.org/html/rfc5222
 	xmlNewChild(ptrFindService, NULL, BAD_CAST "service", BAD_CAST buf);
 
 	xmlDocDumpFormatMemory(request, &xmlbuff, &buffersize, 0);
-	if(!xmlbuff) {
+	if(xmlbuff == NULL) {
 		LM_ERR("findService request xmlDocDumpFormatMemory() failed\n");
 		xmlFreeDoc(request);
 		return doc;

+ 1 - 1
src/modules/lost/utilities.h

@@ -74,7 +74,7 @@ typedef struct LOC
 {
 	char *identity;		/* location idendity (findServiceRequest) */
 	char *urn;			/* service URN (findServiceRequest) */ 
-	char *civic;		/* civic address (findServiceRequest) */
+	char *xpath;		/* civic address (findServiceRequest) */
 	char *geodetic;		/* geodetic location (findServiceRequest) */
 	char *longitude;	/* geo longitude */
 	char *latitude;		/* geo latitude */