From 8fc822e13a8bf8695e475655f647d5d69f99c414 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 20 Sep 2022 11:16:29 -0400 Subject: file: Avoid strange istringstream crash in cmake.org binaries on Alpine Linux Somehow using `istringstream` and `operator >>` to parse an integer crashes on Alpine Linux, at least when compiled with the settings we use for the official `cmake.org` Linux binaries. Since commit fd0c285b12 (file: Fix types of the OFFSET and LIMIT arguments, 2022-01-04, v3.23.0-rc1~133^2), this causes the `file(READ)` command to crash when parsing its `LIMIT` or `OFFSET` argument. Parse the input string with our dedicated helper to avoid the crash. Fixes: #23872 --- Source/cmFileCommand.cxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index da2f15f..fb15a1b 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -199,13 +199,19 @@ bool HandleReadCommand(std::vector const& args, // is there a limit? std::string::size_type sizeLimit = std::string::npos; if (!arguments.Limit.empty()) { - std::istringstream(arguments.Limit) >> sizeLimit; + unsigned long long limit; + if (cmStrToULongLong(arguments.Limit, &limit)) { + sizeLimit = static_cast(limit); + } } // is there an offset? cmsys::ifstream::off_type offset = 0; if (!arguments.Offset.empty()) { - std::istringstream(arguments.Offset) >> offset; + long long off; + if (cmStrToLongLong(arguments.Offset, &off)) { + offset = static_cast(off); + } } file.seekg(offset, std::ios::beg); // explicit ios::beg for IBM VisualAge 6 -- cgit v0.12