FS_LoadFile: don't segfault when trying to open a non-regular file
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 8 Jan 2009 13:09:53 +0000 (13:09 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 8 Jan 2009 13:09:53 +0000 (13:09 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8635 d7cf8633-e32d-0410-b094-e92efae38249

fs.c

diff --git a/fs.c b/fs.c
index 12dfc31..4f7baf9 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -2517,6 +2517,13 @@ unsigned char *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet, f
        if (file)
        {
                filesize = file->real_length;
+               if(filesize < 0)
+               {
+                       Con_Printf("FS_LoadFile(\"%s\", pool, %s, filesizepointer): trying to open a non-regular file\n", path, quiet ? "true" : "false");
+                       FS_Close(file);
+                       return NULL;
+               }
+
                buf = (unsigned char *)Mem_Alloc (pool, filesize + 1);
                buf[filesize] = '\0';
                FS_Read (file, buf, filesize);