From 98383f802aadcd2d469c4d7543e0a2abe8c3cdb9 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Thu, 6 Mar 2014 22:55:07 -0700 Subject: [PATCH] Unicode: check encoding of files given to configure_file. UTF-16 and UTF-32 files are rejected. --- Source/cmMakefile.cxx | 14 ++++++++++++++ Tests/RunCMake/CMakeLists.txt | 1 + Tests/RunCMake/configure_file/CMakeLists.txt | 3 +++ Tests/RunCMake/configure_file/NO-BOM.cmake | 2 ++ Tests/RunCMake/configure_file/NO-BOM.txt.in | 1 + Tests/RunCMake/configure_file/RunCMakeTest.cmake | 8 ++++++++ .../configure_file/UTF16BE-BOM-result.txt | 1 + .../configure_file/UTF16BE-BOM-stderr.txt | 6 ++++++ Tests/RunCMake/configure_file/UTF16BE-BOM.cmake | 2 ++ Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in | Bin 0 -> 26 bytes .../configure_file/UTF16LE-BOM-result.txt | 1 + .../configure_file/UTF16LE-BOM-stderr.txt | 6 ++++++ Tests/RunCMake/configure_file/UTF16LE-BOM.cmake | 2 ++ Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in | Bin 0 -> 26 bytes .../configure_file/UTF32BE-BOM-result.txt | 1 + .../configure_file/UTF32BE-BOM-stderr.txt | 6 ++++++ Tests/RunCMake/configure_file/UTF32BE-BOM.cmake | 2 ++ Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in | Bin 0 -> 52 bytes .../configure_file/UTF32LE-BOM-result.txt | 1 + .../configure_file/UTF32LE-BOM-stderr.txt | 6 ++++++ Tests/RunCMake/configure_file/UTF32LE-BOM.cmake | 2 ++ Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in | Bin 0 -> 52 bytes Tests/RunCMake/configure_file/UTF8-BOM.cmake | 2 ++ Tests/RunCMake/configure_file/UTF8-BOM.txt.in | 1 + bootstrap | 1 + 25 files changed, 69 insertions(+) create mode 100644 Tests/RunCMake/configure_file/CMakeLists.txt create mode 100644 Tests/RunCMake/configure_file/NO-BOM.cmake create mode 100644 Tests/RunCMake/configure_file/NO-BOM.txt.in create mode 100644 Tests/RunCMake/configure_file/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/configure_file/UTF16BE-BOM-result.txt create mode 100644 Tests/RunCMake/configure_file/UTF16BE-BOM-stderr.txt create mode 100644 Tests/RunCMake/configure_file/UTF16BE-BOM.cmake create mode 100644 Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in create mode 100644 Tests/RunCMake/configure_file/UTF16LE-BOM-result.txt create mode 100644 Tests/RunCMake/configure_file/UTF16LE-BOM-stderr.txt create mode 100644 Tests/RunCMake/configure_file/UTF16LE-BOM.cmake create mode 100644 Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in create mode 100644 Tests/RunCMake/configure_file/UTF32BE-BOM-result.txt create mode 100644 Tests/RunCMake/configure_file/UTF32BE-BOM-stderr.txt create mode 100644 Tests/RunCMake/configure_file/UTF32BE-BOM.cmake create mode 100644 Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in create mode 100644 Tests/RunCMake/configure_file/UTF32LE-BOM-result.txt create mode 100644 Tests/RunCMake/configure_file/UTF32LE-BOM-stderr.txt create mode 100644 Tests/RunCMake/configure_file/UTF32LE-BOM.cmake create mode 100644 Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in create mode 100644 Tests/RunCMake/configure_file/UTF8-BOM.cmake create mode 100644 Tests/RunCMake/configure_file/UTF8-BOM.txt.in diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 92177c897..d0e6c30b8 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3518,6 +3518,20 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile, return 0; } + cmsys::FStream::BOM bom = cmsys::FStream::ReadBOM(fin); + if(bom != cmsys::FStream::BOM_None && + bom != cmsys::FStream::BOM_UTF8) + { + cmOStringStream e; + e << "File starts with a Byte-Order-Mark that is not UTF-8:\n " + << sinfile; + this->IssueMessage(cmake::FATAL_ERROR, e.str()); + return 0; + } + // rewind to copy BOM to output file + fin.seekg(0); + + // now copy input to output and expand variables in the // input file at the same time std::string inLine; diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index d401a932d..a8726f48c 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -95,6 +95,7 @@ add_RunCMake_test(TargetPolicies) add_RunCMake_test(alias_targets) add_RunCMake_test(interface_library) add_RunCMake_test(no_install_prefix) +add_RunCMake_test(configure_file) find_package(Qt4 QUIET) find_package(Qt5Core QUIET) diff --git a/Tests/RunCMake/configure_file/CMakeLists.txt b/Tests/RunCMake/configure_file/CMakeLists.txt new file mode 100644 index 000000000..289710955 --- /dev/null +++ b/Tests/RunCMake/configure_file/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.0) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/configure_file/NO-BOM.cmake b/Tests/RunCMake/configure_file/NO-BOM.cmake new file mode 100644 index 000000000..003d52663 --- /dev/null +++ b/Tests/RunCMake/configure_file/NO-BOM.cmake @@ -0,0 +1,2 @@ + +configure_file(NO-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/NO-BOM.txt) diff --git a/Tests/RunCMake/configure_file/NO-BOM.txt.in b/Tests/RunCMake/configure_file/NO-BOM.txt.in new file mode 100644 index 000000000..557db03de --- /dev/null +++ b/Tests/RunCMake/configure_file/NO-BOM.txt.in @@ -0,0 +1 @@ +Hello World diff --git a/Tests/RunCMake/configure_file/RunCMakeTest.cmake b/Tests/RunCMake/configure_file/RunCMakeTest.cmake new file mode 100644 index 000000000..c8bfa570d --- /dev/null +++ b/Tests/RunCMake/configure_file/RunCMakeTest.cmake @@ -0,0 +1,8 @@ +include(RunCMake) + +run_cmake(NO-BOM) +run_cmake(UTF8-BOM) +run_cmake(UTF16LE-BOM) +run_cmake(UTF16BE-BOM) +run_cmake(UTF32LE-BOM) +run_cmake(UTF32BE-BOM) diff --git a/Tests/RunCMake/configure_file/UTF16BE-BOM-result.txt b/Tests/RunCMake/configure_file/UTF16BE-BOM-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF16BE-BOM-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/configure_file/UTF16BE-BOM-stderr.txt b/Tests/RunCMake/configure_file/UTF16BE-BOM-stderr.txt new file mode 100644 index 000000000..5132c4ddb --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF16BE-BOM-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at UTF16BE-BOM.cmake:2 \(configure_file\): + File starts with a Byte-Order-Mark that is not UTF-8: + + .*/Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/configure_file/UTF16BE-BOM.cmake b/Tests/RunCMake/configure_file/UTF16BE-BOM.cmake new file mode 100644 index 000000000..c5707425a --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF16BE-BOM.cmake @@ -0,0 +1,2 @@ + +configure_file(UTF16BE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF16BE-BOM.txt) diff --git a/Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in b/Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in new file mode 100644 index 0000000000000000000000000000000000000000..70fd9cbf7d6e490d148fb44aa9bee4deed65e418 GIT binary patch literal 26 dcmezOpTUD6l_3WR^BEKv!hvKFke$N71psFA1|$Fg literal 0 HcmV?d00001 diff --git a/Tests/RunCMake/configure_file/UTF16LE-BOM-result.txt b/Tests/RunCMake/configure_file/UTF16LE-BOM-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF16LE-BOM-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/configure_file/UTF16LE-BOM-stderr.txt b/Tests/RunCMake/configure_file/UTF16LE-BOM-stderr.txt new file mode 100644 index 000000000..8f997bc71 --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF16LE-BOM-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at UTF16LE-BOM.cmake:2 \(configure_file\): + File starts with a Byte-Order-Mark that is not UTF-8: + + .*/Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/configure_file/UTF16LE-BOM.cmake b/Tests/RunCMake/configure_file/UTF16LE-BOM.cmake new file mode 100644 index 000000000..05c9cd757 --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF16LE-BOM.cmake @@ -0,0 +1,2 @@ + +configure_file(UTF16LE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF16LE-BOM.txt) diff --git a/Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in b/Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in new file mode 100644 index 0000000000000000000000000000000000000000..036f8c536013a31a964862fc12e7fae84d4ed7e2 GIT binary patch literal 26 dcmezW&x0YAAqNQa859`8fn*Voox;Gy003(m1|$Fg literal 0 HcmV?d00001 diff --git a/Tests/RunCMake/configure_file/UTF32BE-BOM-result.txt b/Tests/RunCMake/configure_file/UTF32BE-BOM-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF32BE-BOM-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/configure_file/UTF32BE-BOM-stderr.txt b/Tests/RunCMake/configure_file/UTF32BE-BOM-stderr.txt new file mode 100644 index 000000000..12811aaa2 --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF32BE-BOM-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at UTF32BE-BOM.cmake:2 \(configure_file\): + File starts with a Byte-Order-Mark that is not UTF-8: + + .*/Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/configure_file/UTF32BE-BOM.cmake b/Tests/RunCMake/configure_file/UTF32BE-BOM.cmake new file mode 100644 index 000000000..0c6ea8753 --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF32BE-BOM.cmake @@ -0,0 +1,2 @@ + +configure_file(UTF32BE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF32BE-BOM.txt) diff --git a/Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in b/Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in new file mode 100644 index 0000000000000000000000000000000000000000..c87cfd5ca6947c413ddc47c01371c29c0df0dce9 GIT binary patch literal 52 ncmZQz`1hZIfx!caQ-L@Kit~ZA0uYA-F^F9R#2~p8Am#!9#>ECC literal 0 HcmV?d00001 diff --git a/Tests/RunCMake/configure_file/UTF32LE-BOM-result.txt b/Tests/RunCMake/configure_file/UTF32LE-BOM-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF32LE-BOM-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/configure_file/UTF32LE-BOM-stderr.txt b/Tests/RunCMake/configure_file/UTF32LE-BOM-stderr.txt new file mode 100644 index 000000000..fa9e01a2b --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF32LE-BOM-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at UTF32LE-BOM.cmake:2 \(configure_file\): + File starts with a Byte-Order-Mark that is not UTF-8: + + .*/Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/configure_file/UTF32LE-BOM.cmake b/Tests/RunCMake/configure_file/UTF32LE-BOM.cmake new file mode 100644 index 000000000..b6351b007 --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF32LE-BOM.cmake @@ -0,0 +1,2 @@ + +configure_file(UTF32LE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF32LE-BOM.txt) diff --git a/Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in b/Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in new file mode 100644 index 0000000000000000000000000000000000000000..27c8183bd71c44add30a8b6758bef56de8c5ceb7 GIT binary patch literal 52 ncmezWkAcC1fq@|vh;yJgA4n?zaX1iz*hN4Ll1l+%E+7T~*D?kq literal 0 HcmV?d00001 diff --git a/Tests/RunCMake/configure_file/UTF8-BOM.cmake b/Tests/RunCMake/configure_file/UTF8-BOM.cmake new file mode 100644 index 000000000..af2adae4a --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF8-BOM.cmake @@ -0,0 +1,2 @@ + +configure_file(UTF8-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF8-BOM.txt) diff --git a/Tests/RunCMake/configure_file/UTF8-BOM.txt.in b/Tests/RunCMake/configure_file/UTF8-BOM.txt.in new file mode 100644 index 000000000..abc0acab2 --- /dev/null +++ b/Tests/RunCMake/configure_file/UTF8-BOM.txt.in @@ -0,0 +1 @@ +Hello World diff --git a/bootstrap b/bootstrap index 69dcbce84..4e61f3e6c 100755 --- a/bootstrap +++ b/bootstrap @@ -329,6 +329,7 @@ fi KWSYS_CXX_SOURCES="\ Directory \ EncodingCXX \ + FStream \ Glob \ RegularExpression \ SystemTools"