From 99cb728de481cbc53f4370c3e9d4e9c569d9d395 Mon Sep 17 00:00:00 2001 From: cazfi Date: Sun, 18 Dec 2016 07:25:54 +0000 Subject: [PATCH] Fixed crash when opening file for write fails while bzip2 or xz compression is in use. See bug #25391 git-svn-id: svn://svn.gna.org/svn/freeciv/branches/S2_6@34726 a0f10bec-cc02-0410-94fc-a9cfff90b4cd --- utility/ioz.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/utility/ioz.c b/utility/ioz.c index e742e13ffe..37c3a5b217 100644 --- a/utility/ioz.c +++ b/utility/ioz.c @@ -215,6 +215,7 @@ fz_FILE *fz_from_file(const char *filename, const char *in_mode, } else { #if defined(FREECIV_HAVE_LIBBZ2) || defined(FREECIV_HAVE_LIBLZMA) char test_mode[4]; + sz_strlcpy(test_mode, mode); sz_strlcat(test_mode, "b"); #endif /* FREECIV_HAVE_LIBBZ2 || FREECIV_HAVE_LIBLZMA */ @@ -372,6 +373,10 @@ fz_FILE *fz_from_file(const char *filename, const char *in_mode, fp->u.xz.out_index = 0; fp->u.xz.total_read = 0; fp->u.xz.plain = fc_fopen(filename, mode); + if (!fp->u.xz.plain) { + free(fp); + return NULL; + } } return fp; #endif /* FREECIV_HAVE_LIBLZMA */ @@ -388,9 +393,12 @@ fz_FILE *fz_from_file(const char *filename, const char *in_mode, if (fp->u.bz2.error != BZ_OK) { int tmp_err; /* See comments for similar variable * near BZ2_bzReadOpen() */ + BZ2_bzWriteClose(&tmp_err, fp->u.bz2.file, 0, NULL, NULL); fp->u.bz2.file = NULL; } + } else { + fp->u.bz2.file = NULL; } if (!fp->u.bz2.file) { if (fp->u.bz2.plain) { -- 2.11.4.GIT