summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-02-24 18:02:49 +0100
committerCarl Hetherington <cth@carlh.net>2021-02-24 18:02:49 +0100
commitde795b3e103309210dac9e331d45aacf0f0d884c (patch)
treecb1679edba6f292665bfa10f673f2aed6efb4986
parentc003df64136806705d7662a885ada028a2ba3032 (diff)
Fix config.xml corruption when it contains multi-byte UTF8 characters.
-rw-r--r--src/lib/config.cc2
-rw-r--r--src/lib/dcp_video.cc2
-rw-r--r--src/lib/encode_server.cc8
-rw-r--r--test/config_test.cc13
m---------test/data0
5 files changed, 19 insertions, 6 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc
index d38256673..cc9bd6ffd 100644
--- a/src/lib/config.cc
+++ b/src/lib/config.cc
@@ -984,7 +984,7 @@ Config::write_config () const
if (!f) {
throw FileError (_("Could not open file for writing"), tmp);
}
- checked_fwrite (s.c_str(), s.length(), f, tmp);
+ checked_fwrite (s.c_str(), s.bytes(), f, tmp);
fclose (f);
boost::filesystem::remove (config_file());
boost::filesystem::rename (tmp, config_file());
diff --git a/src/lib/dcp_video.cc b/src/lib/dcp_video.cc
index 153f4997e..ed68299bb 100644
--- a/src/lib/dcp_video.cc
+++ b/src/lib/dcp_video.cc
@@ -226,7 +226,7 @@ DCPVideo::encode_remotely (EncodeServerDescription serv, int timeout)
/* Send XML metadata */
auto xml = doc.write_to_string ("UTF-8");
socket->write (xml.length() + 1);
- socket->write ((uint8_t *) xml.c_str(), xml.length() + 1);
+ socket->write ((uint8_t *) xml.c_str(), xml.bytes() + 1);
/* Send binary data */
LOG_TIMING("start-remote-send thread=%1", thread_id ());
diff --git a/src/lib/encode_server.cc b/src/lib/encode_server.cc
index 92589c573..891b8caac 100644
--- a/src/lib/encode_server.cc
+++ b/src/lib/encode_server.cc
@@ -295,8 +295,8 @@ EncodeServer::broadcast_received ()
try {
auto socket = make_shared<Socket>();
socket->connect (boost::asio::ip::tcp::endpoint (_broadcast.send_endpoint.address(), MAIN_SERVER_PRESENCE_PORT));
- socket->write (xml.length() + 1);
- socket->write ((uint8_t *) xml.c_str(), xml.length() + 1);
+ socket->write (xml.bytes() + 1);
+ socket->write ((uint8_t *) xml.c_str(), xml.bytes() + 1);
} catch (...) {
}
@@ -304,8 +304,8 @@ EncodeServer::broadcast_received ()
try {
auto socket = make_shared<Socket>();
socket->connect (boost::asio::ip::tcp::endpoint (_broadcast.send_endpoint.address(), BATCH_SERVER_PRESENCE_PORT));
- socket->write (xml.length() + 1);
- socket->write ((uint8_t *) xml.c_str(), xml.length() + 1);
+ socket->write (xml.bytes() + 1);
+ socket->write ((uint8_t *) xml.c_str(), xml.bytes() + 1);
} catch (...) {
}
diff --git a/test/config_test.cc b/test/config_test.cc
index ec67a200a..4ca3ba07f 100644
--- a/test/config_test.cc
+++ b/test/config_test.cc
@@ -91,3 +91,16 @@ BOOST_AUTO_TEST_CASE (config_backup_test)
*/
setup_test_config ();
}
+
+
+BOOST_AUTO_TEST_CASE (config_write_utf8_test)
+{
+ boost::filesystem::remove_all ("build/test/config.xml");
+ boost::filesystem::copy_file ("test/data/utf8_config.xml", "build/test/config.xml");
+ Config::override_path = "build/test";
+ Config::drop ();
+ Config::instance()->write();
+
+ check_file ("test/data/utf8_config.xml", "build/test/config.xml");
+}
+
diff --git a/test/data b/test/data
-Subproject 3eb05f5989dcb601bde60c4badc95b66cf46a0c
+Subproject 4c70bad1c502a43d2db17d6d03476e904eb757c