cmake crash on old Linux kernel(4.15.3-1-generic)
I cannot build cmake 3.23.1(also tested 3.16 - same issue reprodused) on Linux with kernel 4.15.3-1-generic. cmake bootstrap(and builded cmake copied from other machine) throw SIGKILL even on --help.
The root of problem is: unlink system call crashes process with empty path.
You can reproduce it simply by typing
~$ unlink ""
Killed
in your command line on Linux with kernel 4.15.3-1-generic
In file cmake-3.23.1/Source/kwsys/SystemTools.cxx you can find this code
Status SystemTools::RemoveFile(std::string const& source)
{
#ifdef _WIN32
std::wstring const& ws = Encoding::ToWindowsExtendedPath(source);
if (DeleteFileW(ws.c_str())) {
return Status::Success();
}
DWORD err = GetLastError();
if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) {
return Status::Success();
}
if (err != ERROR_ACCESS_DENIED) {
return Status::Windows(err);
}
/* The file may be read-only. Try adding write permission. */
mode_t mode;
if (!SystemTools::GetPermissions(source, mode) ||
!SystemTools::SetPermissions(source, S_IWRITE)) {
SetLastError(err);
return Status::Windows(err);
}
const DWORD DIRECTORY_SOFT_LINK_ATTRS =
FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT;
DWORD attrs = GetFileAttributesW(ws.c_str());
if (attrs != INVALID_FILE_ATTRIBUTES &&
(attrs & DIRECTORY_SOFT_LINK_ATTRS) == DIRECTORY_SOFT_LINK_ATTRS &&
RemoveDirectoryW(ws.c_str())) {
return Status::Success();
}
if (DeleteFileW(ws.c_str()) || GetLastError() == ERROR_FILE_NOT_FOUND ||
GetLastError() == ERROR_PATH_NOT_FOUND) {
return Status::Success();
}
/* Try to restore the original permissions. */
SystemTools::SetPermissions(source, mode);
SetLastError(err);
return Status::Windows(err);
#else
if (unlink(source.c_str()) != 0 && errno != ENOENT) {
return Status::POSIX_errno();
}
return Status::Success();
#endif
}
Argument std::string const& source here may be empty string!!! and line
if (unlink(source.c_str()) != 0 && errno != ENOENT) {
will throw SIGKILL on old Linux kernels