Closed DimitriPapadopoulos closed 1 year ago
I am not sure I understand this. How the shell intervention is avoided here exactly?
See: https://docs.python.org/2/library/subprocess.html#replacing-os-popen-os-popen2-os-popen3
On Unix, os.popen2, os.popen3 and os.popen4 also accept a sequence as the command to execute, in which case arguments will be passed directly to the program without shell intervention.
If you pass "ls -l"
, you will actually exec sh ls -l
. The exec
call in the C library, and other similar functions, expect distinct arguments for the path of the executable and the arguments:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html
Ah, got it. Thanks!
This is flagged as a security issue by code analysis tools such as DeepSource.io:
See: https://docs.python.org/2/library/subprocess.html#replacing-os-popen-os-popen2-os-popen3
We do not necessarily have a security issue in this specific case, but why start a shell any way?
Note:
os.popen2
has been deprecated since Python 2.6 and is obsolete, but let's handle that elsewhere: https://docs.python.org/2/library/os.html#os.popen2