From b4e1d9fffeb3a834e30ec13bbd467cecd88f87f9 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 6 Oct 2020 11:26:14 +0200 Subject: [PATCH] Missing error checking on writing KDMs as XML. --- src/encrypted_kdm.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/encrypted_kdm.cc b/src/encrypted_kdm.cc index 071bf870..e8e89870 100644 --- a/src/encrypted_kdm.cc +++ b/src/encrypted_kdm.cc @@ -707,9 +707,15 @@ void EncryptedKDM::as_xml (boost::filesystem::path path) const { FILE* f = fopen_boost (path, "w"); + if (!f) { + throw FileError ("Could not open KDM file for writing", path, errno); + } string const x = as_xml (); - fwrite (x.c_str(), 1, x.length(), f); + size_t const written = fwrite (x.c_str(), 1, x.length(), f); fclose (f); + if (written != x.length()) { + throw FileError ("Could not write to KDM file", path, errno); + } } string -- 2.30.2