Issue Details (XML | Word | Printable)

Key: MODPYTHON-99
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Critical Critical
Assignee: Jim Gallacher
Reporter: Jim Gallacher
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

accessing some request or server object members causes a segfault

Created: 10/Dec/05 07:46 AM   Updated: 05/Mar/06 03:00 PM
Return to search
Component/s: core
Affects Version/s: 3.2.7
Fix Version/s: 3.2.7

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works md-20051209.diff 2005-12-10 07:49 AM Jim Gallacher 1 kB

Resolution Date: 18/Dec/05 02:32 AM


 Description  « Hide
Martin Devara discovered a segfault when accessing some request object members. For example:

def handler(req):
        req.content_type = "text/plain"
        req.write("EE\n")
        a = getattr(req,"allowed_methods");
    return apache.OK

Futher investigation revealed problems with several getter functions in requestobject.c and serverobject.c. The root of the problem seems to be pointer dereferencing errors in the getter code. The affected functions and the members which use them are:

src/requestobject.c
    getreq_rec_ml
        allowed_methods

    getreq_rec_ah
        content_languages
        allowed_xmethods

src/serverobject.c
    getsrv_recmbr_ah
        names
        wild_names

Martin has provided a patch to fix the bug.

(Thanks to Martin for tracking this down and providing the fix.)


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Jim Gallacher added a comment - 10/Dec/05 07:49 AM
Martin's patch (md-20051209.diff)

Jim Gallacher made changes - 10/Dec/05 07:49 AM
Field Original Value New Value
Attachment md-20051209.diff [ 12321248 ]
Jim Gallacher added a comment - 10/Dec/05 07:50 AM
Should we be unit testing the getters and setters for all request and server object members?

Jim Gallacher added a comment - 10/Dec/05 08:53 AM
Some of the unit tests fail after applying Martin's patch. Investigating further reveals that request members are being tested in the unit tests but there are several problems.

One failing test is for req.allowed_xmethods != (). I think this may be a problem with test itself as it seems allowed_xmethods returns None.

The question remains though: why were the tests not detecting the segfaults detailed in this issue?

Nicolas Lehuen added a comment - 10/Dec/05 08:13 PM
Modifying util.c so that tuple_from_array_header and tuple_from_method_list return an empty tuple instead of None fixes the problem, but I still have t(o check whether this change won't break anything else.

Nicolas Lehuen added a comment - 10/Dec/05 08:25 PM
OK, if we modify tuple_from_array_header and tuple_from_method_list, here are the members that would be defined as an empty tuple rather than a None value when the underlying Apache data is not defined :

server.names
server.wildnames
req.allowed_xmethods
req.allowed_methods
req.content_languages

I don't know if we should change the behaviour of those members or simply alter the unit tests, though.




Jim Gallacher added a comment - 10/Dec/05 10:52 PM
The req.allowed_xmethods, req.allowed_methods documentation states that these are a tuples. It seems req.content_languages, server.names, server.wild_names are undocumented.

I don't have mod_python 3.1.4 handy to test but certainly the relavent code has not changed since then. If the problem existed there then I don't think we need to worry about changing the return type since nobody would have been able to access these members anyway.


Repository Revision Date User Message
ASF #357352 Sat Dec 17 17:31:35 UTC 2005 jgallacher Ref MODPYTHON-99
Fixed segfault bug which occured when some request or server object
members were accessed. Affected members are:

  server.names
  server.wild_names
  req.allowed_xmethods
  req.allowed_methods
  req.content_languages

In util.c, changed tuple_from_array_header() and tuple_from_method_list()
to return an empty tuple rather than None when there are 0 elements.

Changed unit tests to check for empty tuple for:
  req.allowed_methods
  req.allowed_xmethods

Added unit tests for:
  server.names
  server.wildnames
  req.content_language
Files Changed
MODIFY /httpd/mod_python/trunk/test/htdocs/tests.py
MODIFY /httpd/mod_python/trunk/src/serverobject.c
MODIFY /httpd/mod_python/trunk/src/util.c
MODIFY /httpd/mod_python/trunk/src/requestobject.c
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/__init__.py
MODIFY /httpd/mod_python/trunk/src/include/mpversion.h

Jim Gallacher made changes - 18/Dec/05 02:32 AM
Fix Version/s 3.2 [ 11060 ]
Assignee Jim Gallacher [ jgallacher ]
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Graham Dumpleton made changes - 05/Mar/06 03:00 PM
Status Resolved [ 5 ] Closed [ 6 ]