aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@src.gnome.org>2001-08-25 07:49:49 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-08-25 07:49:49 +0800
commit2854f067aec69b613f8b964daa4e15bd3311ec25 (patch)
treef888f7ed404a7d7b7d09f66e5116d97ee17adbff /e-util
parent59da64772440a62d81a7bfd831008e4f78c924c0 (diff)
downloadgsoc2013-evolution-2854f067aec69b613f8b964daa4e15bd3311ec25.tar
gsoc2013-evolution-2854f067aec69b613f8b964daa4e15bd3311ec25.tar.gz
gsoc2013-evolution-2854f067aec69b613f8b964daa4e15bd3311ec25.tar.bz2
gsoc2013-evolution-2854f067aec69b613f8b964daa4e15bd3311ec25.tar.lz
gsoc2013-evolution-2854f067aec69b613f8b964daa4e15bd3311ec25.tar.xz
gsoc2013-evolution-2854f067aec69b613f8b964daa4e15bd3311ec25.tar.zst
gsoc2013-evolution-2854f067aec69b613f8b964daa4e15bd3311ec25.zip
robustification
svn path=/trunk/; revision=12468
Diffstat (limited to 'e-util')
-rw-r--r--e-util/ChangeLog4
-rw-r--r--e-util/e-mktemp.c46
2 files changed, 44 insertions, 6 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index eb1c2f02ba..5eca6efaac 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,5 +1,9 @@
2001-08-24 Jeffrey Stedfast <fejj@ximian.com>
+ * e-mktemp.c (get_path): Make more robust.
+
+2001-08-24 Jeffrey Stedfast <fejj@ximian.com>
+
* Makefile.am: Added e-mktemp.[c,h] to the build.
* e-mktemp.c (e_mktemp): A new wrapper around mktemp so that we
diff --git a/e-util/e-mktemp.c b/e-util/e-mktemp.c
index 8164bc145e..e1211da15b 100644
--- a/e-util/e-mktemp.c
+++ b/e-util/e-mktemp.c
@@ -32,6 +32,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
+#include <errno.h>
#ifdef ENABLE_THREADS
#include <pthread.h>
@@ -62,10 +63,37 @@ get_path (gboolean make)
GString *path;
path = g_string_new ("/tmp/evolution-");
- g_string_sprintfa (path, "%d-%d", getuid (), getpid ());
+ g_string_sprintfa (path, "%d-%d", (int) getuid (), (int) getpid ());
- if (make)
- mkdir (path->str, S_IRWXU);
+ if (make) {
+ int ret;
+
+ /* shoot now, ask questions later */
+ ret = mkdir (path->str, S_IRWXU);
+ if (ret == -1) {
+ if (errno == EEXIST) {
+ struct stat st;
+
+ if (stat (path->str, &st) == -1) {
+ /* reset errno */
+ errno = EEXIST;
+ g_string_free (path, TRUE);
+ return NULL;
+ }
+
+ /* make sure this is a directory and belongs to us... */
+ if (!S_ISDIR (st.st_dev) || st.st_uid != getuid ()) {
+ /* eek! this is bad... */
+ g_string_free (path, TRUE);
+ return NULL;
+ }
+ } else {
+ /* some other error...do not pass go, do not collect $200 */
+ g_string_free (path, TRUE);
+ return NULL;
+ }
+ }
+ }
return path;
}
@@ -145,8 +173,10 @@ e_mktemp (const char *template)
ret = mktemp (path->str);
if (ret) {
TEMP_FILES_LOCK ();
- if (!initialized)
+ if (!initialized) {
g_atexit (e_mktemp_cleanup);
+ initialized = TRUE;
+ }
temp_files = g_slist_prepend (temp_files, ret);
g_string_free (path, FALSE);
TEMP_FILES_UNLOCK ();
@@ -177,8 +207,10 @@ e_mkstemp (const char *template)
fd = mkstemp (path->str);
if (fd != -1) {
TEMP_FILES_LOCK ();
- if (!initialized)
+ if (!initialized) {
g_atexit (e_mktemp_cleanup);
+ initialized = TRUE;
+ }
temp_files = g_slist_prepend (temp_files, path->str);
g_string_free (path, FALSE);
TEMP_FILES_UNLOCK ();
@@ -218,8 +250,10 @@ e_mkdtemp (const char *template)
if (tmpdir) {
TEMP_DIRS_LOCK ();
- if (!initialized)
+ if (!initialized) {
g_atexit (e_mktemp_cleanup);
+ initialized = TRUE;
+ }
temp_dirs = g_slist_prepend (temp_dirs, tmpdir);
g_string_free (path, FALSE);
TEMP_DIRS_UNLOCK ();