Skip to content

Commit eaf1784

Browse files
Fix process crashing when receive non UTF-8 data.
1 parent 1fa1376 commit eaf1784

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

docs/release-notes.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Release Notes
55
.. toctree::
66
:maxdepth: 2
77

8+
release-notes/version-5.0.1
89
release-notes/version-5.0.0
910

1011
release-notes/version-4.9.4

docs/release-notes/version-5.0.1.rst

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=============
2+
Version 5.0.1
3+
=============
4+
5+
Version 5.0.1 of mod_wsgi can be obtained from:
6+
7+
https://codeload.github.com/GrahamDumpleton/mod_wsgi/tar.gz/5.0.1
8+
9+
Bugs Fixed
10+
----------
11+
12+
* Fix issue which could result in process crashing when values were supplied
13+
for user/password/realm of HTTP basic authentication which weren't compliant
14+
with UTF-8 encoding format.

src/server/mod_wsgi.c

+52-4
Original file line numberDiff line numberDiff line change
@@ -14885,14 +14885,27 @@ static authn_status wsgi_check_password(request_rec *r, const char *user,
1488514885
adapter = newAuthObject(r, config);
1488614886

1488714887
if (adapter) {
14888+
PyObject *user_string = NULL;
14889+
PyObject *password_string = NULL;
14890+
14891+
#if PY_MAJOR_VERSION >= 3
14892+
user_string = PyUnicode_DecodeLatin1(user, strlen(user), NULL);
14893+
password_string = PyUnicode_DecodeLatin1(password, strlen(password), NULL);
14894+
#else
14895+
user_string = PyString_FromString(user);
14896+
password_string = PyString_FromString(password);
14897+
#endif
14898+
1488814899
vars = Auth_environ(adapter, group);
1488914900

1489014901
Py_INCREF(object);
14891-
args = Py_BuildValue("(Oss)", vars, user, password);
14902+
args = Py_BuildValue("(OOO)", vars, user_string, password_string);
1489214903
result = PyObject_CallObject(object, args);
1489314904
Py_DECREF(args);
1489414905
Py_DECREF(object);
1489514906
Py_DECREF(vars);
14907+
Py_DECREF(user_string);
14908+
Py_DECREF(password_string);
1489614909

1489714910
if (result) {
1489814911
if (result == Py_None) {
@@ -15128,14 +15141,27 @@ static authn_status wsgi_get_realm_hash(request_rec *r, const char *user,
1512815141
adapter = newAuthObject(r, config);
1512915142

1513015143
if (adapter) {
15144+
PyObject *user_string = NULL;
15145+
PyObject *realm_string = NULL;
15146+
15147+
#if PY_MAJOR_VERSION >= 3
15148+
user_string = PyUnicode_DecodeLatin1(user, strlen(user), NULL);
15149+
realm_string = PyUnicode_DecodeLatin1(realm, strlen(realm), NULL);
15150+
#else
15151+
user_string = PyString_FromString(user);
15152+
realm_string = PyString_FromString(realm);
15153+
#endif
15154+
1513115155
vars = Auth_environ(adapter, group);
1513215156

1513315157
Py_INCREF(object);
15134-
args = Py_BuildValue("(Oss)", vars, user, realm);
15158+
args = Py_BuildValue("(OOO)", vars, user_string, realm_string);
1513515159
result = PyObject_CallObject(object, args);
1513615160
Py_DECREF(args);
1513715161
Py_DECREF(object);
1513815162
Py_DECREF(vars);
15163+
Py_DECREF(user_string);
15164+
Py_DECREF(realm_string);
1513915165

1514015166
if (result) {
1514115167
if (result == Py_None) {
@@ -15379,14 +15405,23 @@ static int wsgi_groups_for_user(request_rec *r, WSGIRequestConfig *config,
1537915405
adapter = newAuthObject(r, config);
1538015406

1538115407
if (adapter) {
15408+
PyObject *user_string = NULL;
15409+
15410+
#if PY_MAJOR_VERSION >= 3
15411+
user_string = PyUnicode_DecodeLatin1(r->user, strlen(r->user), NULL);
15412+
#else
15413+
user_string = PyString_FromString(r->user);
15414+
#endif
15415+
1538215416
vars = Auth_environ(adapter, group);
1538315417

1538415418
Py_INCREF(object);
15385-
args = Py_BuildValue("(Os)", vars, r->user);
15419+
args = Py_BuildValue("(OO)", vars, user_string);
1538615420
result = PyObject_CallObject(object, args);
1538715421
Py_DECREF(args);
1538815422
Py_DECREF(object);
1538915423
Py_DECREF(vars);
15424+
Py_DECREF(user_string);
1539015425

1539115426
if (result) {
1539215427
PyObject *iterator;
@@ -15930,14 +15965,27 @@ static int wsgi_hook_check_user_id(request_rec *r)
1593015965
adapter = newAuthObject(r, config);
1593115966

1593215967
if (adapter) {
15968+
PyObject *user_string = NULL;
15969+
PyObject *password_string = NULL;
15970+
15971+
#if PY_MAJOR_VERSION >= 3
15972+
user_string = PyUnicode_DecodeLatin1(r->user, strlen(r->user), NULL);
15973+
password_string = PyUnicode_DecodeLatin1(password, strlen(password), NULL);
15974+
#else
15975+
user_string = PyString_FromString(r->user);
15976+
password_string = PyString_FromString(password);
15977+
#endif
15978+
1593315979
vars = Auth_environ(adapter, group);
1593415980

1593515981
Py_INCREF(object);
15936-
args = Py_BuildValue("(Oss)", vars, r->user, password);
15982+
args = Py_BuildValue("(OOO)", vars, user_string, password_string);
1593715983
result = PyObject_CallObject(object, args);
1593815984
Py_DECREF(args);
1593915985
Py_DECREF(object);
1594015986
Py_DECREF(vars);
15987+
Py_DECREF(user_string);
15988+
Py_DECREF(password_string);
1594115989

1594215990
if (result) {
1594315991
if (result == Py_None) {

0 commit comments

Comments
 (0)