From 6359b7983f4307da6d17766ecefc11453ddaa648 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Tue, 28 Nov 2017 15:28:12 +0200 Subject: [PATCH] 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. --- server/core/config.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server/core/config.c b/server/core/config.c index 083a0ed3c..a15c20e4c 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -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++; }