[PATCH] Make sure imported rating and visibility are within limits.

subsurface at henrik.synth.no subsurface at henrik.synth.no
Tue Jan 29 13:30:02 PST 2013


From: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>

The "visibility" value in MacDive XML files could be a random
string, while it's a value of 0-5 in Subsurface.  Importing an
illegal value (such as "11m") resulted in a segfault from
libpangocairo and an "Invalid UTF-8 string passed to
pango_layout_set_text()".

Signed-off-by: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>
---
 parse-xml.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/parse-xml.c b/parse-xml.c
index 30b6163..9254206 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -458,6 +458,15 @@ static void get_index(char *buffer, void *_i)
 	*i = atoi(buffer);
 }
 
+static void get_rating(char *buffer, void *_i)
+{
+	int *i = _i;
+	int *j = atoi(buffer);
+	if (j >= 0 && j <= 5) {
+		*i = j;
+	}
+}
+
 static void double_to_permil(char *buffer, void *_i)
 {
 	int *i = _i;
@@ -1024,9 +1033,9 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf)
 		return;
 	if (MATCH(".buddy", utf8_string, &dive->buddy))
 		return;
-	if (MATCH(".rating", get_index, &dive->rating))
+	if (MATCH("dive.rating", get_rating, &dive->rating))
 		return;
-	if (MATCH(".visibility", get_index, &dive->visibility))
+	if (MATCH("dive.visibility", get_rating, &dive->visibility))
 		return;
 	if (MATCH(".cylinder.size", cylindersize, &dive->cylinder[cur_cylinder_index].type.size))
 		return;
-- 
1.8.1.1



More information about the subsurface mailing list