]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - fs.c
FS_LoadFile: don't segfault when trying to open a non-regular file
[xonotic/darkplaces.git] / fs.c
diff --git a/fs.c b/fs.c
index c83273e4e746a02ed80326333bbbe4f15a5668b6..4f7baf9d2a6f41e6c00e4097c4efbca26e4dac1f 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -472,7 +472,7 @@ int PK3_BuildFileList (pack_t *pack, const pk3_endOfCentralDir_t *eocd)
        // Load the central directory in memory
        central_dir = (unsigned char *)Mem_Alloc (tempmempool, eocd->cdir_size);
        lseek (pack->handle, eocd->cdir_offset, SEEK_SET);
-       if(read (pack->handle, central_dir, eocd->cdir_size) != eocd->cdir_size)
+       if(read (pack->handle, central_dir, eocd->cdir_size) != (ssize_t) eocd->cdir_size)
        {
                Mem_Free (central_dir);
                return -1;
@@ -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);