]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Check stream status in more cases as suggested by @rgacogne 13362/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 16 Oct 2023 14:25:37 +0000 (16:25 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 16 Oct 2023 14:25:37 +0000 (16:25 +0200)
pdns/recursordist/settings/cxxsupport.cc

index 6a8870068a7f57d63c9c4410978c8a51e0a69bb7..511305930a28bbc990203473a323109751dc57a7 100644 (file)
@@ -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<std::string> forwAndAuthFiles{};