MXS-1529 Prevent endless realloc loop

If the provided config path refers to a directory it can still
be opened and an attempt to read be made. However, as reading
will fail but end-of-file not be reached, we can't rely upon
'feof()' for detecting when to bail out.

As it is a user error to provide a directory as the config path,
that will be detected and deemed an error in a subsequent commit.
This commit is contained in:
Johan Wikman
2017-11-28 15:28:12 +02:00
parent a6e83f41f6
commit 6359b7983f

View File

@ -2448,7 +2448,7 @@ int maxscale_getline(char** dest, int* size, FILE* file)
char* destptr = *dest; char* destptr = *dest;
int offset = 0; int offset = 0;
if (feof(file)) if (feof(file) || ferror(file))
{ {
return 0; return 0;
} }
@ -2471,11 +2471,18 @@ int maxscale_getline(char** dest, int* size, FILE* file)
} }
} }
if ((destptr[offset] = fgetc(file)) == '\n' || feof(file)) int c = fgetc(file);
if ((c == '\n') || (c == EOF))
{ {
destptr[offset] = '\0'; destptr[offset] = '\0';
break; break;
} }
else
{
destptr[offset] = c;
}
offset++; offset++;
} }