[xiph-commits] r9407 - icecast/trunk/icecast/src

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Wed Jun 8 19:21:06 PDT 2005


Author: karl
Date: 2005-06-08 19:21:03 -0700 (Wed, 08 Jun 2005)
New Revision: 9407

Modified:
   icecast/trunk/icecast/src/auth.c
Log:
using .filename causes problems with absolute paths for the temp file, also
test to see if file exists already


Modified: icecast/trunk/icecast/src/auth.c
===================================================================
--- icecast/trunk/icecast/src/auth.c	2005-06-09 01:51:47 UTC (rev 9406)
+++ icecast/trunk/icecast/src/auth.c	2005-06-09 02:21:03 UTC (rev 9407)
@@ -22,6 +22,8 @@
 #include <string.h>
 #include <errno.h>
 #include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #include "auth.h"
 #include "source.h"
@@ -354,6 +356,7 @@
     char *sep;
     char *tmpfile = NULL;
     int tmpfile_len = 0;
+    struct stat file_info;
 
     state = auth->state;
     passwdfile = fopen(state->filename, "rb");
@@ -363,10 +366,16 @@
                 state->filename, strerror(errno));
         return AUTH_FAILED;
     }
-    tmpfile_len = strlen(state->filename) + 6;
+    tmpfile_len = strlen(state->filename) + 5;
     tmpfile = calloc(1, tmpfile_len);
-    sprintf(tmpfile, ".%s.tmp", state->filename);
-
+    snprintf (tmpfile, tmpfile_len, "%s.tmp", state->filename);
+    if (stat (tmpfile, &file_info) == 0)
+    {
+        WARN1 ("temp file \"%s\" exists, rejecting operation", tmpfile);
+        free (tmpfile);
+        fclose (passwdfile);
+        return AUTH_FAILED;
+    }
     tmp_passwdfile = fopen(tmpfile, "wb");
 
     if(tmp_passwdfile == NULL) {



More information about the commits mailing list