While working on line/branch coverage for a unit test, I came across the following code
bool run_command(char *command)
{
FILE *handle = popen(command, "r");
if (handle == nullptr)
{
std::cerr << "" << std::endl;
return false;
}
I've tried many different commands such as
"cat /dev/null | head"
but nothing seems to cause popen to fail. I also wrote a Python script, test.py,
for i in range(10000):
print(i)
and passed "python test.py | head" to popen(). This causes a "broken pipe" error, but popen still returns a valid address.
Is it possible to pass a command string to popen function that will cause it to return null?