Attached patch tries to fix this issue. Not sure whether it's correct.

Sergey
From 7e34ac982d320ede43df1911739324da4f222200 Mon Sep 17 00:00:00 2001
From: Sergey Starosek <[email protected]>
Date: Tue, 15 Jul 2014 16:38:35 +0400
Subject: [PATCH] Fix segfault in world map export
To: [email protected]

Attempting to export to write-protected file/directory
results in NULL file reference and leads to segfault
when writing/closing it.

Signed-off-by: Sergey Starosek <[email protected]>
---
 worldmap-save.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/worldmap-save.c b/worldmap-save.c
index dfce362..0992b8e 100644
--- a/worldmap-save.c
+++ b/worldmap-save.c
@@ -102,10 +102,11 @@ void export_worldmap_HTML(const char *file_name, const bool selected_only)
 	export(&buf, selected_only);
 
 	f = subsurface_fopen(file_name, "w+");
-	if (!f)
+	if (!f) {
 		report_error(translate("gettextFromC", "Can't open file %s"), file_name);
-
-	flush_buffer(&buf, f); /*check for writing errors? */
+	} else {
+		flush_buffer(&buf, f); /*check for writing errors? */
+		fclose(f);
+	}
 	free_buffer(&buf);
-	fclose(f);
 }
-- 
1.8.5.5

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to