[Bf-blender-cvs] [916a216] master: Correction to O_NOFOLLOW commit to make it more portable

Sergey Sharybin noreply at git.blender.org
Tue Apr 22 10:28:45 CEST 2014


Commit: 916a216f440e2791332e83c5a64fa93c05e2db40
Author: Sergey Sharybin
Date:   Tue Apr 22 14:19:54 2014 +0600
https://developer.blender.org/rB916a216f440e2791332e83c5a64fa93c05e2db40

Correction to O_NOFOLLOW commit to make it more portable

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

M	source/blender/blenkernel/intern/blender.c

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

diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index 1b76fc8..92702b0 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -29,6 +29,10 @@
  *  \ingroup bke
  */
 
+#ifndef _GNU_SOURCE
+/* Needed for O_NOFOLLOW on some platforms. */
+#  define _GNU_SOURCE 1
+#endif
 
 #ifndef _WIN32 
 #  include <unistd.h> // for read close
@@ -807,7 +811,7 @@ bool BKE_undo_save_file(const char *filename)
 {
 	UndoElem *uel;
 	MemFileChunk *chunk;
-	int file;
+	int file, oflags;
 
 	if ((U.uiflag & USER_GLOBALUNDO) == 0) {
 		return 0;
@@ -823,8 +827,14 @@ bool BKE_undo_save_file(const char *filename)
 	 * however if this is ever executed explicitly by the user, we may want to allow writing to symlinks.
 	 */
 
+	oflags = O_BINARY | O_WRONLY | O_CREAT | O_TRUNC;
+#ifdef O_NOFOLLOW
 	/* use O_NOFOLLOW to avoid writing to a symlink - use 'O_EXCL' (CVE-2008-1103) */
-	file = BLI_open(filename, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0666);
+	oflags |= O_NOFOLLOW;
+#else
+#  warning "Symbolic links will be followed on undo save, possibly causing CVE-2008-1103"
+#endif
+	file = BLI_open(filename,  oflags, 0666);
 
 	if (file == -1) {
 		fprintf(stderr, "Unable to save '%s': %s\n",




More information about the Bf-blender-cvs mailing list