Issue Details (XML | Word | Printable)

Key: MODPYTHON-84
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Graham Dumpleton
Reporter: Jim Gallacher
Votes: 0
Watchers: 0
Operations

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

req.sendfile(filename) sends an incorrect number of bytes when filename is a symlink

Created: 16/Oct/05 12:24 AM   Updated: 02/Apr/07 11:29 AM
Return to search
Component/s: core
Affects Version/s: 3.1.3, 3.1.4, 3.2.7
Fix Version/s: 3.2.10, 3.3.1

Time Tracking:
Not Specified

Resolution Date: 23/Jun/06 11:15 AM


 Description  « Hide
This issue was reported by Wim Heirman on the mod_python list:

When req.sendfile(filename) is called where filename is a symbolic link, only part of the file is sent to the client (as many bytes as there are characters in the symlink's file reference, so for a symlink pointing to '../index.html' returns the first 13 bytes of the correct file).

Wim suggested changing APR_READ to APR_FINFO_NORM in the apr_stat call in req_sendfile().

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #321349 Sat Oct 15 15:31:46 UTC 2005 jgallacher Fixed req_sendfile(filename) to return the correct number of bytes when
filename points to a symbolic link. The fix needs to be tested on Windows.
Ref MODPYTHON-84
Files Changed
MODIFY /httpd/mod_python/trunk/src/requestobject.c

Jim Gallacher made changes - 16/Oct/05 12:32 AM
Field Original Value New Value
Status Open [ 1 ] In Progress [ 3 ]
Repository Revision Date User Message
ASF #327684 Sat Oct 22 19:24:00 UTC 2005 jgallacher Added unittest for req.sendfile(filename) where filename is a symbolic link.
This test is only run when os.name == 'posix'
Ref MODPYTHON-84
Files Changed
MODIFY /httpd/mod_python/trunk/test/htdocs/tests.py
MODIFY /httpd/mod_python/trunk/test/test.py

Jim Gallacher made changes - 23/Oct/05 11:16 PM
Fix Version/s 3.2 [ 11060 ]
Resolution Fixed [ 1 ]
Status In Progress [ 3 ] Resolved [ 5 ]
Graham Dumpleton made changes - 05/Mar/06 02:34 PM
Status Resolved [ 5 ] Closed [ 6 ]
Graham Dumpleton added a comment - 14/Jun/06 06:37 PM
As per report by Sergey:

  http://www.modpython.org/pipermail/mod_python/2006-May/021276.html

  I'd like to offer the following patch for 3.2.8's sendfile function that
  asks APR to provide less information about a file (which is beneficial
  on Windows as APR doesn't have to construct POSIX protection flags),
  because the only field in use becomes file size. Incidentally, it also
  allows mod_python (plus Apache 2.2 patch) to work with the following
  tweak for APR 1.2.7 (required for Subversion), under Windows and Apache
  2.2.2: http://article.gmane.org/gmane.comp.apache.apr.devel/9389/.

  I didn't test the patch on anything but Windows XP. The error I was
  getting with the setup above was "Could not stat file for reading."
  I also have to mention that the whole thing was compiled with VS 2005
  compiler to support Python 2.4, although I think it's not relevant for
  the patch attached.

with patch:

--- requestobject.c.orig 2006-01-10 19:03:06.000000000 -0500
+++ requestobject.c 2006-05-30 17:11:22.124624100 -0400
@@ -1024,7 +1024,7 @@
 
     Py_BEGIN_ALLOW_THREADS
     status=apr_stat(&finfo, fname,
- APR_FINFO_NORM, self->request_rec->pool);
+ APR_FINFO_SIZE, self->request_rec->pool);
     Py_END_ALLOW_THREADS
     if (status != APR_SUCCESS) {
         PyErr_SetString(PyExc_IOError, "Could not stat file for reading");
@@ -1033,7 +1033,7 @@
     
     Py_BEGIN_ALLOW_THREADS
     status=apr_file_open(&fd, fname,
- APR_READ, finfo.protection,
+ APR_READ, APR_OS_DEFAULT,
                          self->request_rec->pool);
     Py_END_ALLOW_THREADS
     if (status != APR_SUCCESS) {

the original change to fix this symlink issue was causing issues on Win32, plus needs to be changed to work with a APR 1.2.7 change required for subversion to work.

Thus the patch above, seems to be necessary.

At this stage can't see anything wrong with the change.

Graham Dumpleton made changes - 14/Jun/06 06:37 PM
Assignee Jim Gallacher [ jgallacher ] Graham Dumpleton [ grahamd ]
Resolution Fixed [ 1 ]
Status Closed [ 6 ] Reopened [ 4 ]
Repository Revision Date User Message
ASF #416552 Fri Jun 23 03:54:34 UTC 2006 jgallacher The original change to fix the symlink issue for req.sendfile was causing
problems on Win32, plus needs to be changed to work with a APR 1.2.7
change required for subversion to work. (MODPYTHON-84)
Bug reported and patch provided by Sergey A. Lipnevich.
Files Changed
MODIFY /httpd/mod_python/trunk/src/requestobject.c

Repository Revision Date User Message
ASF #416554 Fri Jun 23 03:58:49 UTC 2006 jgallacher Backport of additional fix for symlink problem in req.sendfile, as reported
by Sergey A. Lipnevich. (MODPYTHON-84)
Files Changed
MODIFY /httpd/mod_python/branches/3.2.x/src/requestobject.c

Jim Gallacher made changes - 23/Jun/06 11:15 AM
Status Reopened [ 4 ] Resolved [ 5 ]
Fix Version/s 3.2.8 [ 12310840 ]
Fix Version/s 3.2.7 [ 11060 ]
Resolution Fixed [ 1 ]
Graham Dumpleton made changes - 08/Aug/06 01:57 AM
Fix Version/s 3.3 [ 12310101 ]
Fix Version/s 3.2.8 [ 12310840 ]
Fix Version/s 3.2.10 [ 12312029 ]
Repository Revision Date User Message
ASF #429537 Tue Aug 08 01:59:19 UTC 2006 grahamd (MODPYTHON-84) Further fix related to symlinks in req.sendfile() not noted
in changes list of documentation.
Files Changed
MODIFY /httpd/mod_python/trunk/Doc/appendixc.tex

Graham Dumpleton made changes - 02/Apr/07 11:29 AM
Status Resolved [ 5 ] Closed [ 6 ]