From 3b4db8da2b4335115ccd80591fa69d74276c83db Mon Sep 17 00:00:00 2001 From: Martin Zenzes Date: Thu, 3 Mar 2016 16:13:58 +0100 Subject: [PATCH] parseConfigMapFromYamlNode: add proper checking of input filename otherwise, it happily tries to parse nonexisting files. which should fail, and loudly so! Signed-off-by: Martin Zenzes --- src/ConfigData.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ConfigData.cpp b/src/ConfigData.cpp index 245aa52..7a5fda1 100644 --- a/src/ConfigData.cpp +++ b/src/ConfigData.cpp @@ -56,6 +56,14 @@ namespace configmaps { ConfigMap ConfigMap::fromYamlFile(const string &filename, bool loadURI) { std::ifstream fin(filename.c_str()); + if (!fin.good()) { + fprintf(stderr, "ERROR: ConfigMap::fromYamlFile failed! " + "Could not open input file \"%s\"\n", + filename.c_str()); + // wouldn't it be better to throw? the returned map is empty, which + // might not be what the caller actually wants? + return ConfigMap(); + } ConfigMap map = fromYamlStream(fin); if(loadURI) { std::string pathToFile = getPathOfFile(filename);