From: Alex Stancu Date: Thu, 18 Jun 2020 10:51:26 +0000 (+0000) Subject: Merge "When env variable SCRIPTS_DIR is unset the code reads or writes from a path... X-Git-Tag: 1.0.3~16 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fo1-interface.git;a=commitdiff_plain;h=3472441e3d90935c770f84c449b6541784afd6a5;hp=19cb6d014bb190c158f28a7ececd203d50ca1996 Merge "When env variable SCRIPTS_DIR is unset the code reads or writes from a path NULL. I suggest to fix this and use a default instead." --- diff --git a/ntsimulator/src/utils/utils.c b/ntsimulator/src/utils/utils.c index 7c7f56c..217675b 100644 --- a/ntsimulator/src/utils/utils.c +++ b/ntsimulator/src/utils/utils.c @@ -410,7 +410,26 @@ char* readConfigFileInString(void) char * buffer = 0; long length; char config_file[200]; - sprintf(config_file, "%s/configuration.json", getenv("SCRIPTS_DIR")); + + //sprintf(config_file, "%s/configuration.json", getenv("SCRIPTS_DIR")); + + // --> recommended fix, Karl Koch, Deutsche Telekom AG, 22. 5. 2020. + // Path to config_file contains NULL when env variable is unset. + char *scripts_dir = getenv("SCRIPTS_DIR"); + char *scripts_dir_default = "/opt/dev/ntsimulator/scripts"; + + if(NULL != scripts_dir) + { + sprintf(config_file, "%s/configuration.json", scripts_dir); + } + else + { + sprintf(config_file, "%s/configuration.json", scripts_dir_default); + printf("warning: opening config file in default path: <%s>\n", + config_file); + } + // end of fix <-- + FILE * f = fopen (config_file, "rb"); if (f) @@ -438,7 +457,26 @@ char* readConfigFileInString(void) void writeConfigFile(char *config) { char config_file[200]; - sprintf(config_file, "%s/configuration.json", getenv("SCRIPTS_DIR")); + + //sprintf(config_file, "%s/configuration.json", getenv("SCRIPTS_DIR")); + + // --> recommended fix, Karl Koch, Deutsche Telekom AG, 22. 5. 2020. + // Path to config_file contains NULL when env variable is unset. + char *scripts_dir = getenv("SCRIPTS_DIR"); + char *scripts_dir_default = "/opt/dev/ntsimulator/scripts"; + + if(NULL != scripts_dir) + { + sprintf(config_file, "%s/configuration.json", scripts_dir); + } + else + { + sprintf(config_file, "%s/configuration.json", scripts_dir_default); + printf("warning: opening config file in default path: <%s>\n", + config_file); + } + // end of fix <-- + FILE * f = fopen (config_file, "w"); if (f)