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:
@ -2448,7 +2448,7 @@ int maxscale_getline(char** dest, int* size, FILE* file)
|
||||
char* destptr = *dest;
|
||||
int offset = 0;
|
||||
|
||||
if (feof(file))
|
||||
if (feof(file) || ferror(file))
|
||||
{
|
||||
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';
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
destptr[offset] = c;
|
||||
}
|
||||
|
||||
offset++;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user