]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/common/vfs.c
handle forbidden dir exclusions properly now
[xonotic/netradiant.git] / tools / quake3 / common / vfs.c
index 547ee70a960ab3f2b272b5b10f2a896d60252869..9c75cb3a8549b0dc5fba3d1cc63069ce3672ffdd 100644 (file)
@@ -46,8 +46,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <sys/stat.h>
 
 #include "cmdlib.h"
+#include "filematch.h"
 #include "mathlib.h"
-#include <glib.h>
 #include "inout.h"
 #include "vfs.h"
 #include "unzip.h"
@@ -161,9 +161,17 @@ void vfsInitDirectory (const char *path)
 
   for(j = 0; j < g_numForbiddenDirs; ++j)
   {
-    if(!Q_stricmp(path, g_strForbiddenDirs[j])
-    || (strlen(path) > strlen(g_strForbiddenDirs[j]) && path[strlen(path) - strlen(g_strForbiddenDirs[j]) - 1] == '/' && !Q_stricmp(path + strlen(path) - strlen(g_strForbiddenDirs[j]), g_strForbiddenDirs[j])))
+    char* dbuf = g_strdup(path);
+    if(*dbuf && dbuf[strlen(dbuf)-1] == '/')
+      dbuf[strlen(dbuf)-1] = 0;
+    const char *p = strrchr(dbuf, '/');
+    p = (p ? (p+1) : dbuf);
+    if(matchpattern(p, g_strForbiddenDirs[j], TRUE))
+    {
+      g_free(dbuf);
       break;
+    }
+    g_free(dbuf);
   }
   if(j < g_numForbiddenDirs)
     return;
@@ -192,8 +200,12 @@ void vfsInitDirectory (const char *path)
           break;
 
         for(j = 0; j < g_numForbiddenDirs; ++j)
-          if(!Q_stricmp(name, g_strForbiddenDirs[j]))
+        {
+          const char *p = strrchr(name, '/');
+          p = (p ? (p+1) : name);
+          if(matchpattern(p, g_strForbiddenDirs[j], TRUE))
             break;
+        }
         if(j < g_numForbiddenDirs)
           continue;
 
@@ -298,9 +310,16 @@ int vfsLoadFile (const char *filename, void **bufferptr, int index)
     
     *bufferptr = safe_malloc (len+1);
     if (*bufferptr == NULL)
-      return -1;
+       {
+               fclose(f);
+               return -1;
+       }
     
-    fread (*bufferptr, 1, len, f);
+    if(fread (*bufferptr, 1, len, f) != (size_t) len)
+       {
+               fclose(f);
+               return -1;
+       }
     fclose (f);
     
     // we need to end the buffer with a 0
@@ -335,9 +354,16 @@ int vfsLoadFile (const char *filename, void **bufferptr, int index)
         
         *bufferptr = safe_malloc (len+1);
         if (*bufferptr == NULL)
+               {
+                 fclose(f);
           return -1;
+               }
         
-        fread (*bufferptr, 1, len, f);
+        if(fread (*bufferptr, 1, len, f) != (size_t) len)
+               {
+                 fclose(f);
+          return -1;
+               }
         fclose (f);
         
         // we need to end the buffer with a 0