mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Linux: Completely fix gcc-5 "Invalid characters encountered" issue on mount. It was caused by an issue of gcc-5 STL implementation that is causing char* pointers retrieved from std::string using c_str method to become invalid in the child of a child process (after two fork calls). The workaround is to first copy the std:string values in the child before calling the second fork.
This commit is contained in:
@@ -53,13 +53,33 @@ namespace VeraCrypt
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
int argIndex = 0;
|
int argIndex = 0;
|
||||||
|
/* Workaround for gcc 5.X issue related to the use of STL (string and list) with muliple fork calls.
|
||||||
|
*
|
||||||
|
* The char* pointers retrieved from the elements of parameter "arguments" are no longer valid after
|
||||||
|
* a second fork is called. "arguments" was created in the parent of the current child process.
|
||||||
|
*
|
||||||
|
* The only solution is to copy the elements of "arguments" parameter in a local string array on this
|
||||||
|
* child process and then use char* pointers retrieved from this local copies before calling fork.
|
||||||
|
*
|
||||||
|
* gcc 4.x doesn't suffer from this issue.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
string argsCopy[array_capacity (args)];
|
||||||
if (!execFunctor)
|
if (!execFunctor)
|
||||||
args[argIndex++] = const_cast <char*> (processName.c_str());
|
{
|
||||||
|
argsCopy[argIndex++] = processName;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (const string &arg, arguments)
|
foreach (const string &arg, arguments)
|
||||||
{
|
{
|
||||||
args[argIndex++] = const_cast <char*> (arg.c_str());
|
argsCopy[argIndex++] = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < argIndex; i++)
|
||||||
|
{
|
||||||
|
args[i] = const_cast <char*> (argsCopy[i].c_str());
|
||||||
|
}
|
||||||
|
|
||||||
args[argIndex] = nullptr;
|
args[argIndex] = nullptr;
|
||||||
|
|
||||||
if (inputData)
|
if (inputData)
|
||||||
|
|||||||
Reference in New Issue
Block a user