From: Otto Moerbeek Date: Mon, 16 Oct 2023 14:25:37 +0000 (+0200) Subject: Check stream status in more cases as suggested by @rgacogne X-Git-Tag: rec-5.0.0-alpha2~1^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F13362%2Fhead;p=thirdparty%2Fpdns.git Check stream status in more cases as suggested by @rgacogne --- diff --git a/pdns/recursordist/settings/cxxsupport.cc b/pdns/recursordist/settings/cxxsupport.cc index 6a8870068a..511305930a 100644 --- a/pdns/recursordist/settings/cxxsupport.cc +++ b/pdns/recursordist/settings/cxxsupport.cc @@ -185,6 +185,11 @@ static void possiblyConvertACLFile(const string& includeDir, const string& apiDi ofconf << "# Generated by pdns-recursor REST API, DO NOT EDIT" << endl; ofconf << yaml << endl; ofconf.close(); + if (ofconf.bad()) { + log->error(Logr::Error, "Error writing YAML", "to", Logging::Loggable(tmpfilename)); + unlink(tmpfilename.c_str()); + throw runtime_error("YAML Conversion"); + } if (rename(path.c_str(), (path + ".converted").c_str()) != 0) { int err = errno; log->error(Logr::Error, err, "Rename failed", "file", Logging::Loggable(path), "to", Logging::Loggable(path + ".converted")); @@ -230,9 +235,14 @@ static void fileCopy(const string& src, const string& dst, Logr::log_t log) throw runtime_error("YAML Conversion"); } } - ofconf.close(); ifconf.close(); + ofconf.close(); + if (ofconf.bad()) { + log->error(Logr::Error, "Error writing YAML", "to", Logging::Loggable(dst)); + throw runtime_error("YAML Conversion"); + } } + static void possiblyConvertForwardsandAuths(const std::string& includeDir, const std::string& apiDir, Logr::log_t log) { std::vector forwAndAuthFiles{};