summaryrefslogtreecommitdiff
path: root/src/configreader.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-02-10 00:11:02 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-02-10 00:11:02 +0000
commitab9d28a14772e60109aa0bd834d7dcbbe7b9302d (patch)
tree8a23ccf0e41b4bb10e06b5eccb7561fc7bd5b0fa /src/configreader.cpp
parent5f56457576dbaedd8b8c228b245059bee3d8fcfc (diff)
When opening a file to read, check its not a directory with stat()
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6557 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/configreader.cpp')
-rw-r--r--src/configreader.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 64641805c..9e13dfae1 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -1428,12 +1428,18 @@ bool ServerConfig::ReadFile(file_cache &F, const char* fname)
{
/* Leaves us with just the path */
std::string newfile = confpath.substr(0, pos) + std::string("/") + fname;
+ if (!FileExists(newfile.c_str()))
+ return false;
file = fopen(newfile.c_str(), "r");
}
}
else
+ {
+ if (!FileExists(fname))
+ return false;
file = fopen(fname, "r");
+ }
if (file)
{
@@ -1460,11 +1466,16 @@ bool ServerConfig::ReadFile(file_cache &F, const char* fname)
bool ServerConfig::FileExists(const char* file)
{
+ struct stat sb;
+ if (stat(file, &sb) == -1)
+ return false;
+
+ if ((sb.st_mode & S_IFDIR) > 0)
+ return false;
+
FILE *input;
if ((input = fopen (file, "r")) == NULL)
- {
return false;
- }
else
{
fclose(input);