diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-05-12 21:50:34 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-05-12 21:50:34 +0100 |
commit | cceee6b8e23138e5a16e6aef23759a8c60ef872e (patch) | |
tree | 4a743b186828a6eacdd904e4868e9fc3ad1a153e | |
parent | 9064f7b9c347f913089bfea94d65ad3afc11ccf4 (diff) |
Fix crash in getconfstr() when not finding certain strings in configuration file.
-rw-r--r-- | config.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -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; } |