/pidgin/main: 92e7c7cfb29b: Set file permissions before writing ...

Mark Doliner mark at kingant.net
Sun Dec 30 22:32:18 EST 2012


Changeset: 92e7c7cfb29bcd8653a9027e0714625d78629c02
Author:	 Mark Doliner <mark at kingant.net>
Date:	 2012-12-30 19:32 -0800
Branch:	 default
URL: http://hg.pidgin.im/pidgin/main/rev/92e7c7cfb29b

Description:

Set file permissions before writing data to it, and use the existing fd.

Static code analysis done by Chris Wysopal and Veracode found that there
is the brief window when files written using this function (e.g. accounts.xml)
have the default permissions according to your umask.  In some
circumstances this could mean the file itself is world-readable.  In
most cases this won't matter because the file is written to your ~/.purple/
directory and this directory should not be world readable.

We don't think this is a huge problem... but better to be safe than sorry.

diffstat:

 libpurple/util.c |  18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diffs (35 lines):

diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -3000,6 +3000,15 @@ purple_util_write_data_to_file_absolute(
 		return FALSE;
 	}
 
+#ifndef _WIN32
+	/* Set file permissions */
+	if (fchmod(fileno(file), S_IRUSR | S_IWUSR) == -1)
+	{
+		purple_debug_error("util", "Error setting permissions of %s: %s\n",
+				filename_temp, g_strerror(errno));
+	}
+#endif
+
 	/* Write to file */
 	real_size = (size == -1) ? strlen(data) : (size_t) size;
 	byteswritten = fwrite(data, 1, real_size, file);
@@ -3079,15 +3088,6 @@ purple_util_write_data_to_file_absolute(
 		return FALSE;
 	}
 
-#ifndef _WIN32
-	/* Set file permissions */
-	if (chmod(filename_temp, S_IRUSR | S_IWUSR) == -1)
-	{
-		purple_debug_error("util", "Error setting permissions of file %s: %s\n",
-						 filename_temp, g_strerror(errno));
-	}
-#endif
-
 	/* Rename to the REAL name */
 	if (g_rename(filename_temp, filename_full) == -1)
 	{



More information about the Commits mailing list