char *pwd = new char[3001];
if (GETCWD(pwd, 3000) == nullptr) {
if (pwd != nullptr) { //
delete[] pwd;
}
return cvm::error("Error: cannot get the path of the current working directory.\n",
COLVARS_BUG_ERROR);
}
replica_list_file =
(std::string(pwd)+std::string(PATHSEP)+
this->name+"."+replica_id+".files.txt");
The conditional will never be false, but pwd will not be initialized; thus so std::string(pwd) later is UB.
In src/colvarbias_meta.cpp, there's
GETCWD(BUF, SIZE)
macro used to wrapgetcwd
function to put current working dir intoBUF
. However, whenstd::filesystem
is available, a different implementation is used, which does not changeBUF
but instead returns a temporary C-string: https://github.com/Colvars/colvars/blob/0e0ce447630e95f2cd0322b1699e7f60b526ef9f/src/colvarbias_meta.cpp#L25C1-L30C7This is not ok with how
GETCWD
is later used:The conditional will never be false, but
pwd
will not be initialized; thus sostd::string(pwd)
later is UB.