Check for empty basename in GetFileContentOrDie() (#1558)

An empty basename would mean a directory path is returned by
GetFullPathOrDie(), which then leads to a cryptic exception when trying
to read from it using the istreambuf_iterator:

"basic_filebuf::underflow error reading the file: iostream error"
master
Michael Grupp 2019-04-02 16:01:51 +02:00 committed by Wally B. Feed
parent 98197cff4f
commit ab0ceacbed
1 changed files with 1 additions and 0 deletions

View File

@ -47,6 +47,7 @@ std::string ConfigurationFileResolver::GetFullPathOrDie(
std::string ConfigurationFileResolver::GetFileContentOrDie(
const std::string& basename) {
CHECK(!basename.empty()) << "File basename cannot be empty." << basename;
const std::string filename = GetFullPathOrDie(basename);
std::ifstream stream(filename.c_str());
return std::string((std::istreambuf_iterator<char>(stream)),