]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
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 12dfc317ccdb46d6ef591b0101ed2f3281077eb9..4f7baf9d2a6f41e6c00e4097c4efbca26e4dac1f 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);