From 092c202a5e64852d38b3157c0d8c7b51b866a7f2 Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 29 May 2005 15:54:21 +0000 Subject: Added include stack to detect looped includes git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1553 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/inspircd.cpp | 2 ++ src/inspircd_io.cpp | 33 ++++++++++++++++++++++++++++----- src/modules.cpp | 3 +++ 3 files changed, 33 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 9dc99857b..37c98bb1b 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -120,6 +120,7 @@ int ep, lep, sep; #endif bool has_been_netsplit = false; +extern std::vector include_stack; typedef nspace::hash_map, irc::StrHashComp> user_hash; typedef nspace::hash_map, irc::StrHashComp> chan_hash; @@ -263,6 +264,7 @@ void ReadConfig(bool bail, userrec* user) char AH[MAXBUF],AP[MAXBUF],AF[MAXBUF],DNT[MAXBUF],pfreq[MAXBUF],thold[MAXBUF],sqmax[MAXBUF],rqmax[MAXBUF]; ConnectClass c; std::stringstream errstr; + include_stack.clear(); if (!LoadConf(CONFIG_FILE,&config_f,&errstr)) { diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp index e28290ec5..de3d23689 100644 --- a/src/inspircd_io.cpp +++ b/src/inspircd_io.cpp @@ -37,6 +37,7 @@ extern int openSockfd[MAXSOCKS]; extern time_t TIME; extern bool unlimitcore; extern int MaxConn; +std::vector include_stack; void WriteOpers(char* text, ...); @@ -298,6 +299,15 @@ bool LoadConf(const char* filename, std::stringstream *target, std::stringstream } // Fix the chmod of the file to restrict it to the current user and group chmod(filename,0600); + for (int t = 0; t < include_stack.size(); t++) + { + if (std::string(filename) == include_stack[t]) + { + *errorstream << "File " << filename << " is included recursively (looped inclusion)." << endl; + return false; + } + } + include_stack.push_back(filename); // now open it FILE* conf = fopen(filename,"r"); char buffer[MAXBUF]; @@ -314,6 +324,7 @@ bool LoadConf(const char* filename, std::stringstream *target, std::stringstream if (!strncmp(buffer," modules; extern std::vector factory; +extern std::vector include_stack; + extern time_t TIME; extern int LogLevel; @@ -818,6 +820,7 @@ Module* Server::FindModule(std::string name) ConfigReader::ConfigReader() { + include_stack.clear(); this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out); this->errorlog = new std::stringstream(std::stringstream::in | std::stringstream::out); this->readerror = LoadConf(CONFIG_FILE,this->cache,this->errorlog); -- cgit v1.2.3