From 7a79a6b8dfdc33cbd784c8ee83212b4e177292f8 Mon Sep 17 00:00:00 2001 From: Jay Dolan Date: Sat, 14 Jan 2006 00:08:29 +0000 Subject: [PATCH] Fixed FS_OpenFile to only open regular files on filesystem. Fixes server crash with e.g. 'cmd download maps' --- src/files.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/files.c b/src/files.c index 7a471f8..93c6f4c 100644 --- a/src/files.c +++ b/src/files.c @@ -22,6 +22,8 @@ * 02111-1307, USA. */ +#include + #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -199,7 +201,7 @@ FS_FOpenFile Finds the file in the search path. returns filesize and an open FILE * Used for streaming data out of either a pak file or -a seperate file. +a seperate file.< =========== */ int file_from_pak = 0; @@ -207,6 +209,7 @@ int file_from_pak = 0; int FS_FOpenFile(char *filename, FILE **file){ searchpath_t *search; char netpath[MAX_OSPATH]; + struct stat sbuf; pack_t *pak; int i; filelink_t *link; @@ -250,10 +253,12 @@ int FS_FOpenFile(char *filename, FILE **file){ Com_sprintf(netpath, sizeof(netpath), "%s/%s", search->filename, filename); - *file = fopen(netpath, "rb"); - if(!*file) + if(stat(netpath, &sbuf) == -1 || !S_ISREG(sbuf.st_mode)) continue; - + + if((*file = fopen(netpath, "rb")) == NULL) + continue; + Com_DPrintf("FindFile: %s\n", netpath); return FS_filelength(*file);