diff options
author | Craig Scott <craig.scott@crascit.com> | 2019-10-28 10:50:09 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-10-28 10:50:22 (GMT) |
commit | cdcc173e236963ad598b098d2d807d0489aa3d42 (patch) | |
tree | 4b6a98ee254b90f50cf1185fca98bd9fcafbfde3 /Tests | |
parent | e03b677e703f84c9d1a2875083d1290db16eb4ad (diff) | |
parent | 82cdb26c93b595e3791818cc8f24dfc6935eb8a8 (diff) | |
download | CMake-cdcc173e236963ad598b098d2d807d0489aa3d42.zip CMake-cdcc173e236963ad598b098d2d807d0489aa3d42.tar.gz CMake-cdcc173e236963ad598b098d2d807d0489aa3d42.tar.bz2 |
Merge topic 'project-version-buffer-overflow'
82cdb26c93 project: Fix potential buffer write-past-end for version components
15a0b0d046 Help: math() expressions must be representable as signed 64-bit
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3948
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/project/RunCMakeTest.cmake | 1 | ||||
-rw-r--r-- | Tests/RunCMake/project/VersionMax.cmake | 32 |
2 files changed, 33 insertions, 0 deletions
diff --git a/Tests/RunCMake/project/RunCMakeTest.cmake b/Tests/RunCMake/project/RunCMakeTest.cmake index 8f43a51..6914699 100644 --- a/Tests/RunCMake/project/RunCMakeTest.cmake +++ b/Tests/RunCMake/project/RunCMakeTest.cmake @@ -22,6 +22,7 @@ run_cmake(VersionInvalid) run_cmake(VersionMissingLanguages) run_cmake(VersionMissingValueOkay) run_cmake(VersionTwice) +run_cmake(VersionMax) run_cmake(CMP0048-OLD) run_cmake(CMP0048-OLD-VERSION) diff --git a/Tests/RunCMake/project/VersionMax.cmake b/Tests/RunCMake/project/VersionMax.cmake new file mode 100644 index 0000000..e955364 --- /dev/null +++ b/Tests/RunCMake/project/VersionMax.cmake @@ -0,0 +1,32 @@ +cmake_policy(SET CMP0048 NEW) +cmake_policy(SET CMP0096 OLD) + +enable_language(C) +include(CheckTypeSize) +check_type_size(unsigned __sizeOfUnsigned BUILTIN_TYPES_ONLY LANGUAGE C) + +# We can't use math() to compute this because it only supports up to +# 64-bit signed integers, so hard-code the types we expect to encounter +if(__sizeOfUnsigned EQUAL 0) + message(STATUS "Multi-architecture build, skipping project version check") + return() +elseif(__sizeOfUnsigned EQUAL 4) + set(maxVal 4294967295) +elseif(__sizeOfUnsigned EQUAL 8) + set(maxVal 18446744073709551615) +else() + message(FATAL_ERROR + "Test needs to be updated for unsigned integer size ${__sizeOfUnsigned}") +endif() + +# The real value of this test is when an address sanitizer is enabled. +# It catches situations where the size of the buffer used to compute or +# hold the version components as strings is too small. +project(ProjectA VERSION ${maxVal}.${maxVal}.${maxVal}.${maxVal} LANGUAGES NONE) + +if(NOT ${PROJECT_VERSION_MAJOR} EQUAL ${maxVal}) + message(FATAL_ERROR "Project version number parsing failed round trip.\n" + "Expected: ${maxVal}\n" + "Computed: ${PROJECT_VERSION_MAJOR}" + ) +endif() |