Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion openvpn/common/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,23 @@ inline BufferPtr read_binary(const std::string &filename,
std::ifstream ifs(filename.c_str(), std::ios::binary);
#endif // OPENVPN_PLATFORM_WIN

if (!ifs)
if (ifs.fail() || !ifs.good())
OPENVPN_THROW(open_file_error, "cannot open for read: " << filename);

if (filename.rfind("/dev/fd/", 0) == 0) {
std::string ret;
std::string line;
while (std::getline(ifs, line))
{
ret += line;
ret += '\n';
}
const size_t len = ret.length();
BufferPtr buf = BufferAllocatedRc::Create(len, 0);
buf->write((unsigned char *)ret.c_str(), len);
return buf;
}

// get length of file
ifs.seekg(0, std::ios::end);
const std::streamsize length = ifs.tellg();
Expand Down
2 changes: 1 addition & 1 deletion openvpn/options/merge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class ProfileMerge
profile_dir = !profile_dir_override.empty() ? profile_dir_override : path::dirname(profile_path);
basename_ = path::basename(profile_path);
const std::string ext = path::ext(basename_);
if (profile_ext.empty() || string::strcasecmp(ext, profile_ext) == 0)
if (profile_ext.empty() || string::strcasecmp(ext, profile_ext) == 0 || profile_path.rfind("/dev/fd/", 0) == 0)
{
orig_profile_content = read_text_utf8(profile_path, max_size);
total_size = orig_profile_content.size();
Expand Down