[Bf-blender-cvs] [8b815c7ce56] blender-v2.91-release: Fix T81271: Fix crash in BLI_gzopen on Windows

Robert Guetzkow noreply at git.blender.org
Mon Nov 16 13:22:32 CET 2020


Commit: 8b815c7ce565b707fca9e9793bbec9784856f0f9
Author: Robert Guetzkow
Date:   Mon Nov 16 13:04:23 2020 +0100
Branches: blender-v2.91-release
https://developer.blender.org/rB8b815c7ce565b707fca9e9793bbec9784856f0f9

Fix T81271: Fix crash in BLI_gzopen on Windows

Previously the return value of `ufopen` wasn't checked and if it failed,
`NULL` was passed into `fclose()` which resulted in a crash. This patch
avoids this by returning from `BLI_gzopen` when the file cannot be created.

Reviewed By: sebbas, iss

Differential Revision: https://developer.blender.org/D9576

===================================================================

M	source/blender/blenlib/intern/fileops.c

===================================================================

diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index 413c2007b1b..bb218995c83 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -357,7 +357,12 @@ void *BLI_gzopen(const char *filename, const char *mode)
 
   /* xxx Creates file before transcribing the path */
   if (mode[0] == 'w') {
-    fclose(ufopen(filename, "a"));
+    FILE *file = ufopen(filename, "a");
+    if (file == NULL) {
+      /* File couldn't be opened, e.g. due to permission error. */
+      return NULL;
+    }
+    fclose(file);
   }
 
   /* temporary #if until we update all libraries to 1.2.7



More information about the Bf-blender-cvs mailing list