Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-04-22 10:56:53 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-04-22 11:21:00 +0400
commit367722470aa2eada43614cd558f468b4beea851d (patch)
treef537f6b592699e69f3de5c45d6e097b66446c69d /source/blender/blenkernel/intern/blender.c
parent41b37c007c334d714d7b52edb1aeaec7087b56d4 (diff)
Don't follow symlinks when writing autosave or quit.blend
D253 from Lawrence D'Oliveiro
Diffstat (limited to 'source/blender/blenkernel/intern/blender.c')
-rw-r--r--source/blender/blenkernel/intern/blender.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index c238052c268..1b76fc856df 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -798,12 +798,15 @@ const char *BKE_undo_get_name(int nr, int *active)
return NULL;
}
-/* saves .blend using undo buffer, returns 1 == success */
-int BKE_undo_save_file(const char *filename)
+/**
+ * Saves .blend using undo buffer.
+ *
+ * \return success.
+ */
+bool BKE_undo_save_file(const char *filename)
{
UndoElem *uel;
MemFileChunk *chunk;
- const int flag = O_BINARY + O_WRONLY + O_CREAT + O_TRUNC + O_EXCL;
int file;
if ((U.uiflag & USER_GLOBALUNDO) == 0) {
@@ -816,16 +819,12 @@ int BKE_undo_save_file(const char *filename)
return 0;
}
- /* first try create the file, if it exists call without 'O_CREAT',
- * to avoid writing to a symlink - use 'O_EXCL' (CVE-2008-1103) */
- errno = 0;
- file = BLI_open(filename, flag, 0666);
- if (file == -1) {
- if (errno == EEXIST) {
- errno = 0;
- file = BLI_open(filename, flag & ~O_CREAT, 0666);
- }
- }
+ /* note: This is currently used for autosave and 'quit.blend', where _not_ following symlinks is OK,
+ * however if this is ever executed explicitly by the user, we may want to allow writing to symlinks.
+ */
+
+ /* 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);
if (file == -1) {
fprintf(stderr, "Unable to save '%s': %s\n",