Sfoglia il codice sorgente

lost: use buffer size for snprintf

(cherry picked from commit be2d3bfe537a692efa8cdc2bd4e4441eed5d0840)
Daniel-Constantin Mierla 9 mesi fa
parent
commit
264e23e830
1 ha cambiato i file con 6 aggiunte e 6 eliminazioni
  1. 6 6
      src/modules/lost/utilities.c

+ 6 - 6
src/modules/lost/utilities.c

@@ -1047,7 +1047,7 @@ int lost_parse_geo(xmlNodePtr node, p_lost_loc_t loc)
 	if(loc->latitude == NULL)
 	if(loc->latitude == NULL)
 		goto err;
 		goto err;
 
 
-	snprintf(loc->latitude, len, "%s", (char *)bufLat);
+	snprintf(loc->latitude, len + 1, "%s", (char *)bufLat);
 
 
 	/* logitude */
 	/* logitude */
 	len = strlen((char *)bufLon);
 	len = strlen((char *)bufLon);
@@ -1057,7 +1057,7 @@ int lost_parse_geo(xmlNodePtr node, p_lost_loc_t loc)
 		goto err;
 		goto err;
 	}
 	}
 
 
-	snprintf(loc->longitude, len, "%s", (char *)bufLon);
+	snprintf(loc->longitude, len + 1, "%s", (char *)bufLon);
 
 
 	/* altitude */
 	/* altitude */
 	if(scan == 3) {
 	if(scan == 3) {
@@ -1071,13 +1071,13 @@ int lost_parse_geo(xmlNodePtr node, p_lost_loc_t loc)
 			goto err;
 			goto err;
 		}
 		}
 		
 		
-		snprintf(loc->altitude, len, "%s", (char *)bufAlt);
+		snprintf(loc->altitude, len + 1, "%s", (char *)bufAlt);
 	}
 	}
 
 
 	/* geolocation */
 	/* geolocation */
 	len = strlen((char *)bufLat) + strlen((char *)bufLon) + 1;
 	len = strlen((char *)bufLat) + strlen((char *)bufLon) + 1;
 	if((scan == 3) && (lost_geoloc_3d == 1)) {
 	if((scan == 3) && (lost_geoloc_3d == 1)) {
-		len += strlen((char *)bufAlt);
+		len += strlen((char *)bufAlt) + 1;
 	}
 	}
 	loc->geodetic = (char *)pkg_malloc(len + 1);
 	loc->geodetic = (char *)pkg_malloc(len + 1);
 	if(loc->geodetic == NULL) {
 	if(loc->geodetic == NULL) {
@@ -1089,9 +1089,9 @@ int lost_parse_geo(xmlNodePtr node, p_lost_loc_t loc)
 	}
 	}
 	if((scan == 3) && (lost_geoloc_3d == 1)) {
 	if((scan == 3) && (lost_geoloc_3d == 1)) {
 		s_profile = LOST_PRO_GEO3D;
 		s_profile = LOST_PRO_GEO3D;
-		snprintf(loc->geodetic, len, "%s %s %s", (char *)bufLat, (char *)bufLon, (char *)bufAlt);
+		snprintf(loc->geodetic, len + 1, "%s %s %s", (char *)bufLat, (char *)bufLon, (char *)bufAlt);
 	} else {
 	} else {
-		snprintf(loc->geodetic, len, "%s %s", (char *)bufLat, (char *)bufLon);
+		snprintf(loc->geodetic, len + 1, "%s %s", (char *)bufLat, (char *)bufLon);
 	}
 	}
 
 
 	/* find <radius> element */
 	/* find <radius> element */