return "";
}
// firstly clean up the line by stripping spaces from the start and end and converting tabs to spaces
- for (int d = 0; d < strlen(buffer); d++)
+ for (unsigned int d = 0; d < strlen(buffer); d++)
if ((buffer[d]) == 9)
buffer[d] = ' ';
while ((buffer[0] == ' ') && (strlen(buffer)>0)) buffer++;
return "";
else if (buffer[0] == '#')
return "";
- for (int c = 0; c < strlen(buffer); c++)
+ for (unsigned int c = 0; c < strlen(buffer); c++)
{
// convert all spaces that are OUTSIDE quotes into hardspace (0xA0) as this will make them easier to
// search and replace later :)
}
// turn our hardspace back into softspace
- for (int d = 0; d < parsedata.length(); d++)
+ for (unsigned int d = 0; d < parsedata.length(); d++)
{
if (parsedata[d] == '\xA0')
parsedata[d] = ' ';
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("");
}
// 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++)
+ for (unsigned int t = 0; t < include_stack.size(); t++)
{
if (std::string(filename) == include_stack[t])
{
{
while (!feof(conf))
{
- if (fgets(buffer, MAXBUF, conf))
+ if (fgets_safe(buffer, MAXBUF, conf))
{
if ((!feof(conf)) && (buffer) && (strlen(buffer)))
{
char confpath[10240],newconf[10240];
// include file directive
buf += 15; // advance to filename
- for (int j = 0; j < strlen(buffer); j++)
+ for (unsigned int j = 0; j < strlen(buf); j++)
{
+ if (buf[j] == '\\')
+ buf[j] = '/';
if (buf[j] == '"')
{
buf[j] = '\0';
std::string newstuff = merge.str();
*target << newstuff;
}
+ else
+ {
+ // the error propogates up to its parent recursively
+ // causing the config reader to bail at the top level.
+ fclose(conf);
+ return false;
+ }
}
else
{
{
int ptr = 0;
char buffer[65535], c_tag[MAXBUF], c, lastc;
- int in_token, in_quotes, tptr, j, idx = 0;
+ int in_token, in_quotes, tptr, idx = 0;
char* key;
const char* buf = config->str().c_str();
key++;
}
key++;
- for (j = 0; j < strlen(key); j++)
+ for (unsigned j = 0; j < strlen(key); j++)
{
if (key[j] == '"')
{