Bug Description
In psutil/arch/sunos/proc.c, after creating py_envval, the code checks py_envname (the previously created variable) instead of py_envval. If PyUnicode_DecodeFSDefault returns NULL for py_envval, the NULL is passed to PyDict_SetItem, causing a segfault.
Location
psutil/arch/sunos/proc.c:214-216
Code
py_envval = PyUnicode_DecodeFSDefault(dm + 1);
if (!py_envname) // BUG: should check py_envval
goto error;
Impact
If PyUnicode_DecodeFSDefault fails for the environment value (e.g., invalid encoding), py_envval is NULL, but the check passes because py_envname was set earlier. The NULL py_envval is then passed to PyDict_SetItem(py_envs, py_envname, py_envval), which dereferences it, causing a crash.
Suggested Fix
py_envval = PyUnicode_DecodeFSDefault(dm + 1);
if (!py_envval) // Fixed: check the correct variable
goto error;
Environment
- OS: Solaris / illumos
- psutil version: current main (commit 7b6a9a6)
- Affected API:
psutil.Process().environ()
Bug Description
In
psutil/arch/sunos/proc.c, after creatingpy_envval, the code checkspy_envname(the previously created variable) instead ofpy_envval. IfPyUnicode_DecodeFSDefaultreturns NULL forpy_envval, the NULL is passed toPyDict_SetItem, causing a segfault.Location
psutil/arch/sunos/proc.c:214-216Code
Impact
If
PyUnicode_DecodeFSDefaultfails for the environment value (e.g., invalid encoding),py_envvalis NULL, but the check passes becausepy_envnamewas set earlier. The NULLpy_envvalis then passed toPyDict_SetItem(py_envs, py_envname, py_envval), which dereferences it, causing a crash.Suggested Fix
Environment
psutil.Process().environ()