From 28d85094a3d73449f44a185347b7bc55aa537aee Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Mon, 25 Aug 2025 11:57:27 +0800 Subject: [PATCH] fix CVE-2025-9301 (cherry picked from commit e934365a3211b45131443ead993c3147260ce28b) --- backport-CVE-2025-9301.patch | 63 ++++++++++++++++++++++++++++++++++++ cmake.spec | 23 ++++++------- 2 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 backport-CVE-2025-9301.patch diff --git a/backport-CVE-2025-9301.patch b/backport-CVE-2025-9301.patch new file mode 100644 index 0000000..b238500 --- /dev/null +++ b/backport-CVE-2025-9301.patch @@ -0,0 +1,63 @@ +From 37e27f71bc356d880c908040cd0cb68fa2c371b8 Mon Sep 17 00:00:00 2001 +From: Tyler Yankee +Date: Wed, 13 Aug 2025 15:22:28 -0400 +Subject: [PATCH] foreach: Explicitly skip replay without iterations + +As written, foreach loops with a trailing `IN` (i.e., no loop +variable(s) given) lead to an assertion error. Handle this case by +exiting early when we know the loop won't execute anything. + +Fixes: #27135 +--- + Source/cmForEachCommand.cxx | 3 +++ + Tests/RunCMake/foreach/RunCMakeTest.cmake | 1 + + Tests/RunCMake/foreach/TrailingIn-result.txt | 1 + + Tests/RunCMake/foreach/TrailingIn.cmake | 5 +++++ + 4 files changed, 10 insertions(+) + create mode 100644 Tests/RunCMake/foreach/TrailingIn-result.txt + create mode 100644 Tests/RunCMake/foreach/TrailingIn.cmake + +diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx +index 96867e26587..8b741183885 100644 +--- a/Source/cmForEachCommand.cxx ++++ b/Source/cmForEachCommand.cxx +@@ -100,6 +100,9 @@ bool cmForEachFunctionBlocker::ArgumentsMatch(cmListFileFunction const& lff, + bool cmForEachFunctionBlocker::Replay( + std::vector functions, cmExecutionStatus& inStatus) + { ++ if (this->Args.size() == this->IterationVarsCount) { ++ return true; ++ } + return this->ZipLists ? this->ReplayZipLists(functions, inStatus) + : this->ReplayItems(functions, inStatus); + } +diff --git a/Tests/RunCMake/foreach/RunCMakeTest.cmake b/Tests/RunCMake/foreach/RunCMakeTest.cmake +index 15ca477043f..acfc742ea6f 100644 +--- a/Tests/RunCMake/foreach/RunCMakeTest.cmake ++++ b/Tests/RunCMake/foreach/RunCMakeTest.cmake +@@ -22,3 +22,4 @@ run_cmake(foreach-RANGE-invalid-test) + run_cmake(foreach-RANGE-out-of-range-test) + run_cmake(foreach-var-scope-CMP0124-OLD) + run_cmake(foreach-var-scope-CMP0124-NEW) ++run_cmake(TrailingIn) +diff --git a/Tests/RunCMake/foreach/TrailingIn-result.txt b/Tests/RunCMake/foreach/TrailingIn-result.txt +new file mode 100644 +index 00000000000..573541ac970 +--- /dev/null ++++ b/Tests/RunCMake/foreach/TrailingIn-result.txt +@@ -0,0 +1 @@ ++0 +diff --git a/Tests/RunCMake/foreach/TrailingIn.cmake b/Tests/RunCMake/foreach/TrailingIn.cmake +new file mode 100644 +index 00000000000..e2b5b2f21f7 +--- /dev/null ++++ b/Tests/RunCMake/foreach/TrailingIn.cmake +@@ -0,0 +1,5 @@ ++foreach(v IN) ++endforeach() ++ ++foreach(v1 v2 IN) ++endforeach() +-- +GitLab + diff --git a/cmake.spec b/cmake.spec index a6bdda1..d8f4893 100644 --- a/cmake.spec +++ b/cmake.spec @@ -22,7 +22,7 @@ Name: cmake Version: 3.27.9 -Release: 7 +Release: 8 Summary: Cross-platform make system License: BSD and MIT and zlib URL: http://www.cmake.org @@ -36,6 +36,8 @@ Patch0: cmake-findruby.patch Patch1: cmake-3.27.9-fix-cxx-standard-check-issue.patch Patch2: cmake-3.22.0-sw.patch Patch3: backport-cmake-aarch64-ilp32-support.patch +# https://gitlab.kitware.com/cmake/cmake/-/commit/37e27f71bc356d880c908040cd0cb68fa2c371b8 +Patch6001: backport-CVE-2025-9301.patch BuildRequires: coreutils findutils gcc-c++ gcc-gfortran sed @@ -128,7 +130,7 @@ BuildArch: noarch Documentation for cmake. %prep -%setup -n cmake-%{version}%{?versuf} +%setup -qn cmake-%{version}%{?versuf} %patch 0 -p1 %patch 1 -p1 %ifarch sw_64 @@ -137,11 +139,7 @@ Documentation for cmake. %ifarch aarch64_ilp32 %patch 3 -p1 %endif - -echo '#!%{__python3}' > %{name}.prov -echo '#!%{__python3}' > %{name}.req -tail -n +2 %{SOURCE4} >> %{name}.prov -tail -n +2 %{SOURCE5} >> %{name}.req +%patch 6001 -p1 %build export CFLAGS=`echo %{optflags} | sed 's/-g\b/-s/g'` @@ -190,9 +188,9 @@ rm -f %{buildroot}%{_emacs_sitelispdir} install -p -m0644 -D %{SOURCE2} %{buildroot}%{rpm_macros_dir}/macros.cmake sed -i -e "s|@@CMAKE_VERSION@@|%{version}|" -e "s|@@CMAKE_MAJOR_VERSION@@|3|" %{buildroot}%{rpm_macros_dir}/macros.cmake touch -r %{SOURCE2} %{buildroot}%{rpm_macros_dir}/macros.cmake -install -p -m0644 -D %{SOURCE3} %{buildroot}%{_prefix}/lib/rpm/fileattrs/cmake.attr -install -p -m0755 -D cmake.prov %{buildroot}%{_prefix}/lib/rpm/cmake.prov -install -p -m0755 -D cmake.req %{buildroot}%{_prefix}/lib/rpm/cmake.req +install -p -m0644 -D %{S:3} %{buildroot}%{_fileattrsdir}/cmake.attr +install -p -m0755 -D %{S:4} %{buildroot}%{_rpmconfigdir}/cmake.prov +install -p -m0755 -D %{S:5} %{buildroot}%{_rpmconfigdir}/cmake.req install -d %{buildroot}%{_libdir}/cmake find Source Utilities -type f -iname copy\* cp -p Source/kwsys/Copyright.txt ./Copyright_kwsys @@ -281,7 +279,7 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || : %files rpm-macros %{rpm_macros_dir}/macros.cmake -%{_rpmconfigdir}/fileattrs/cmake.attr +%{_fileattrsdir}/cmake.attr %{_rpmconfigdir}/cmake.prov %{_rpmconfigdir}/cmake.req @@ -302,6 +300,9 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || : %exclude %{_pkgdocdir}/Copyright.txt %changelog +* Mon Aug 25 2025 Funda Wang - 3.27.9-8 +- fix CVE-2025-9301 + * Fri May 16 2025 mahailiang - 3.27.9-7 - not modify lib64 to lib on sw_64 - fix sw_64 portmidi Could NOT find JNI -- Gitee