Skip to content

Commit 7f3ccdb

Browse files
committed
fix: fix the corner case when variable is None
Sometimes application developers set the value of an environment variable to None. This fix adds a guard for mitigating this issue to prevent python from crashing. Signed-off-by: Tianrui Wei <tianrui@tianruiwei.com>
1 parent b9dedfe commit 7f3ccdb

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Lib/subprocess.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,8 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
18151815
if env is not None:
18161816
env_list = []
18171817
for k, v in env.items():
1818+
if v is None:
1819+
continue
18181820
k = os.fsencode(k)
18191821
if b'=' in k:
18201822
raise ValueError("illegal environment variable name")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
When parsing environment variables passed by caller to subprocess.Popen,
2+
check the actual value of the variable is not set to None. Lack of this
3+
checking causes crashes in python programs.

0 commit comments

Comments
 (0)