Skip to content

Commit 73ff103

Browse files
Don't attempt to set environment variables when no password entry for user ID.
1 parent 76302e6 commit 73ff103

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

docs/release-notes/version-4.4.19.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ Version 4.4.19 of mod_wsgi can be obtained from:
99
For details on the availability of Windows binaries see:
1010

1111
https://github.com/GrahamDumpleton/mod_wsgi/tree/master/win32
12+
13+
Bugs Fixed
14+
----------
15+
16+
1. Daemon mode processes were crashing when attempting to set ``USER``,
17+
``USERNAME``, ``LOGNAME`` or ``HOME`` when no password entry could be
18+
found for the current user ID. Now do not attempt to set these if the
19+
user ID doesn't have a password file entry.

src/server/wsgi_interp.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ InterpreterObject *newInterpreterObject(const char *name)
631631

632632
pwent = getpwuid(geteuid());
633633

634-
if (getenv("USER")) {
634+
if (pwent && getenv("USER")) {
635635
#if PY_MAJOR_VERSION >= 3
636636
key = PyUnicode_FromString("USER");
637637
value = PyUnicode_Decode(pwent->pw_name,
@@ -649,7 +649,7 @@ InterpreterObject *newInterpreterObject(const char *name)
649649
Py_DECREF(value);
650650
}
651651

652-
if (getenv("USERNAME")) {
652+
if (pwent && getenv("USERNAME")) {
653653
#if PY_MAJOR_VERSION >= 3
654654
key = PyUnicode_FromString("USERNAME");
655655
value = PyUnicode_Decode(pwent->pw_name,
@@ -667,7 +667,7 @@ InterpreterObject *newInterpreterObject(const char *name)
667667
Py_DECREF(value);
668668
}
669669

670-
if (getenv("LOGNAME")) {
670+
if (pwent && getenv("LOGNAME")) {
671671
#if PY_MAJOR_VERSION >= 3
672672
key = PyUnicode_FromString("LOGNAME");
673673
value = PyUnicode_Decode(pwent->pw_name,
@@ -718,20 +718,24 @@ InterpreterObject *newInterpreterObject(const char *name)
718718
struct passwd *pwent;
719719

720720
pwent = getpwuid(geteuid());
721+
722+
if (pwent) {
721723
#if PY_MAJOR_VERSION >= 3
722-
key = PyUnicode_FromString("HOME");
723-
value = PyUnicode_Decode(pwent->pw_dir, strlen(pwent->pw_dir),
724-
Py_FileSystemDefaultEncoding,
725-
"surrogateescape");
724+
key = PyUnicode_FromString("HOME");
725+
value = PyUnicode_Decode(pwent->pw_dir,
726+
strlen(pwent->pw_dir),
727+
Py_FileSystemDefaultEncoding,
728+
"surrogateescape");
726729
#else
727-
key = PyString_FromString("HOME");
728-
value = PyString_FromString(pwent->pw_dir);
730+
key = PyString_FromString("HOME");
731+
value = PyString_FromString(pwent->pw_dir);
729732
#endif
730733

731-
PyObject_SetItem(object, key, value);
734+
PyObject_SetItem(object, key, value);
732735

733-
Py_DECREF(key);
734-
Py_DECREF(value);
736+
Py_DECREF(key);
737+
Py_DECREF(value);
738+
}
735739
}
736740

737741
Py_DECREF(module);

0 commit comments

Comments
 (0)