diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/inspircd_io.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp index c3f725c14..96a751d65 100644 --- a/src/inspircd_io.cpp +++ b/src/inspircd_io.cpp @@ -286,6 +286,20 @@ std::string ConfProcess(char* buffer, long linenumber, std::stringstream* errors return parsedata; } +int fgets_safe(char* buffer, size_t maxsize, FILE* &file) +{ + char c_read = '\0'; + unsigned int bufptr = 0; + while ((!feof(file)) && (c_read != '\n') && (c_read != '\r') && (bufptr < maxsize)) + { + c_read = fgetc(file); + if ((c_read != '\n') && (c_read != '\r')) + buffer[bufptr++] = c_read; + } + buffer[bufptr] = '\0'; + return bufptr; +} + bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream) { target->str(""); @@ -315,7 +329,7 @@ bool LoadConf(const char* filename, std::stringstream *target, std::stringstream { while (!feof(conf)) { - if (fgets(buffer, MAXBUF, conf)) + if (fgets_safe(buffer, MAXBUF, conf)) { if ((!feof(conf)) && (buffer) && (strlen(buffer))) { |