From cceee6b8e23138e5a16e6aef23759a8c60ef872e Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sun, 12 May 2019 21:50:34 +0100 Subject: Fix crash in getconfstr() when not finding certain strings in configuration file. --- config.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index 168b780..78190f5 100644 --- a/config.c +++ b/config.c @@ -7,6 +7,7 @@ int getconfstr(char *confname, char *filename, char* dest) { FILE *fp; char *ret; char str[MAXCHAR]; + int found = 0; // Have we found the configuration option? // Set strings to zero-length to begin dest[0] = '\0'; @@ -39,14 +40,14 @@ int getconfstr(char *confname, char *filename, char* dest) { // If the resulting temporary string contains the requested option name, // we have found our configuration option and it is in the current 'str' if (!(ret = strstr(substr, confname)) == 0) { + found = 1; break; } } // If we got here, then either we found the configuration option or we ran out of file - // If str is NULL then we ran out of file - if (ret == NULL) { + if (!found) { printf("Error reading configuration option '%s', did not find it in configuration file '%s'.\n", confname, filename); return 0; } -- cgit v1.2.3