You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Roger Espel Llima <es...@iagora.net> on 2000/07/18 16:35:39 UTC

BUG in $r->filename

There's a bug in the `filename' method of mod_perl's Apache request
object: in some conditions, old invalid ->finfo data stays cached.

Demonstration: in a PerlTransHandler, do $r->filename("/") followed by
$r->filename("/no/such/file.html").  At least under Linux, the cached
stat() value for "/", with S_ISDIR set, doesn't get overwritten by the
second failed stat("/no/such/file.html").  This causes mod_mime to set
the MIME type to DIR_MAGIC_TYPE ("httpd/unix-directory") instead of
"text/html" as the filename indicates.

The problem is in the 'filename' function of src/modules/perl/Apache.xs,
which does a stat() without checking its return value.  

Here's a patch; I'm not 100% sure that it's completely the-right-thing,
but it seems to fix the problem.  The 'filename' code hasn't changed at
all between versions 1.21 (which I'm using), 1.24 (the current release)
and the daily CVS sources linked from perl.apache.org, so this patch
should work with all these versions.


------------------------------ begin patch --------------------------------
--- Apache.xs.org	Tue Jul 18 15:51:18 2000
+++ Apache.xs	Tue Jul 18 15:52:33 2000
@@ -1762,8 +1762,12 @@
     CODE:
     get_set_PVp(r->filename,r->pool);
 #ifndef WIN32
-    if(items > 1)
-	stat(r->filename, &r->finfo);
+    if(items > 1) {
+        if (stat(r->filename, &r->finfo) < 0) {
+	    r->finfo.st_mode = 0;
+	    laststatval = 0;
+	}
+    }
 #endif
 
     OUTPUT:
------------------------------ end patch --------------------------------

-- 
Roger Espel Llima, espel@iagora.net
http://www.iagora.com/~espel/index.html