Commented: (MODPYTHON-187) Hang on subscripted access to
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Apache Server configuration support > Apache Mod-Python > Commented: (MODPYTHON-187) Hang on subscripted access to




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Commented: (MODPYTHON-187) Hang on subscripted access to  
Jim Gallacher (JIRA)


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-29-06 06:18 AM

[ http://issues.apache.org/jira/brows...243
1107 ]

Jim Gallacher commented on MODPYTHON-187:
-----------------------------------------

The problem seems to be in the tableobject.c function table_subscript().

subprocess_env.get['SCRIPT_FILENAME'] is being evaluated in the post rea
d request phase. It would seem that req.add_common_vars adds a key for SCRIP
T_FILENAME to the table, but since the filename has not been translated yet 
its value is NULL.

table_subscript() retrieves the value with the following bit of code:

while (i--)
if (elts[i].key) {
if (apr_strnatcasecmp(elts[i].key, k) == 0) {
PyObject *v = PyString_FromString(elts[i].val);
PyList_Insert(list, 0, v);
Py_DECREF(v);
}
}

The problem is with the PyString_FromString. According to the Python docs, t
he parameter passed must not be NULL and it will not be checked. I assume th
is is the origin of the segfault.

Something like the following seems to fix the problem.

The following code snippet seems to fix the problem, and is attached as MP18
7-2006-08-28-jgallacher-1.diff. Am I correct in doing the PY_INCREF(v)??

while (i--)
if (elts[i].key) {
if (apr_strnatcasecmp(elts[i].key, k) == 0) {
-                PyObject *v = PyString_FromString(elts[i].val);
+                PyObject *v = NULL;
+                if (elts[i].val != NULL) {
+                    v = PyString_FromString(elts[i].val);
+                } else {
+                    v = Py_None;
+                    Py_INCREF(v);
+                }
PyList_Insert(list, 0, v);
Py_DECREF(v);





> Hang on subscripted access to request.subprocess_env.
> -----------------------------------------------------
>
>                 Key: MODPYTHON-187
>                 URL: http://issues.apache.org/jira/browse/MODPYTHON-187
>             Project: mod_python
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.10
>         Environment: Apache:     2.0.59
> ModPython:  3.2.10
> Python:     2.4
> OS:         Windows Server 2003
>            Reporter: Alan Kennedy
>
> When subscripted access is used to access variable 'SCRIPT_FILENAME' in th
e request.subprocess_env table/mapping, the code hangs.
> The following snippet illustrates the problem.
> # -=-=-=-=-=-=
> def postreadrequesthandler(request):
>   request.add_common_vars()
>   value = request.subprocess_env['SCRIPT_FILENAME']    # This hangs
> # value = request.subprocess_env.get('SCRIPT_FILENAME')# This works
>   return apache.OK
> # -=-=-=-=-=-=
> The strange thing is that the .get() access works fine: only the subscript
 hangs?
> If anyone is wondering about a use-case, I don't actually have one. I was just ite
rating over the contents of the request.subprocess_env using a for loop (code below)
, and found that the code hung when accessing 'SCRIPT_FILENAME', and not for any oth
er
variable.
> # -=-=-=
> request.add_common_vars()
> d = {}
> for sek in request.subprocess_env.keys():
>   d[sek] = request.subprocess_env[sek]
> # -=-=-=






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:31 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register