From: Heiko Schlittermann (HS12-RIPE) Date: Fri, 30 Dec 2016 11:35:47 +0000 (+0100) Subject: Tidy and add \0 after string_append() for relative .includes X-Git-Tag: exim-4_89_RC1~53 X-Git-Url: https://vcs.fsf.org/?p=exim.git;a=commitdiff_plain;h=8e7e13572850c65857fd9d2da8b341e1ca3e98b7;hp=8cfd0f7b84730e10238219bd5b93677519ecbb16 Tidy and add \0 after string_append() for relative .includes --- diff --git a/src/src/readconf.c b/src/src/readconf.c index c5bd41d47..cd18431f4 100644 --- a/src/src/readconf.c +++ b/src/src/readconf.c @@ -3377,18 +3377,19 @@ logging configuration errors (it changes for .included files) whereas config_main_filename is the name shown by -bP. Failure to open a configuration file is a serious disaster. */ -if (config_file != NULL) +if (config_file) { - uschar *slash = Ustrrchr(filename, '/'); + uschar *last_slash = Ustrrchr(filename, '/'); config_filename = config_main_filename = string_copy(filename); - /* the config_main_directory we need for the $config_dir expansion. + /* The config_main_directory we need for the $config_dir expansion. + config_main_filename we need for $config_file expansion. And config_dir is the directory of the current configuration, used for relative .includes. We do need to know it's name, as we change our working directory later. */ if (filename[0] == '/') - config_main_directory = slash > filename ? string_copyn(filename, slash - filename) : US"/"; + config_main_directory = last_slash == filename ? US"/" : string_copyn(filename, last_slash - filename); else { /* relative configuration file name: working dir + / + basename(filename) */ @@ -3396,7 +3397,6 @@ if (config_file != NULL) char buf[PATH_MAX]; int offset = 0; int size = 0; - const uschar *p = Ustrrchr(filename, '/'); if (getcwd(buf, PATH_MAX) == NULL) { @@ -3407,11 +3407,13 @@ if (config_file != NULL) /* If the dir does not end with a "/", append one */ if (config_main_directory[offset-1] != '/') - string_cat(config_main_directory, &size, &offset, US"/"); + config_main_directory = string_catn(config_main_directory, &size, &offset, US"/", 1); /* If the config file contains a "/", extract the directory part */ - if (p) - string_catn(config_main_directory, &size, &offset, filename, p - filename); + if (last_slash) + config_main_directory = string_catn(config_main_directory, &size, &offset, filename, last_slash - filename); + + config_main_directory[offset] = '\0'; } config_directory = config_main_directory; }