Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: Dev

Re: PL_laststatval

 

 

ModPerl dev RSS feed   Index | Next | Previous | View Threaded


dougm at pobox

Jul 24, 2000, 4:15 PM

Post #1 of 3 (1190 views)
Permalink
Re: PL_laststatval

On Mon, 24 Jul 2000, Eric Cholet wrote:

> Hi,
>
> I want to fix this bug in r->filename. Currently it does this:
>
> CODE:
> get_set_PVp(r->filename,r->pool);
> #ifndef WIN32
> if(items > 1)
> stat(r->filename, &r->finfo);
> #endif
>
> The return code for stat() is not checked, therefore the stat
> cache is left at its previous value which doesn't seem right.
> What I want to do is this:
> CODE:
> get_set_PVp(r->filename,r->pool);
> #ifndef WIN32
> if(items > 1)
> - stat(r->filename, &r->finfo);
> + laststatval = stat(r->filename, &r->finfo);
> #endif

missing one piece from roger's patch, something like so:

if ((laststatval = stat(...)) < 0) {
r->finfo.st_mode = 0;
}

> What bothers me is this code in r->finfo:
>
> CODE:
> statcache = r->finfo;
> if (r->finfo.st_mode) {
> laststatval = 0;
> }
> else {
> laststatval = -1;
> }
>
> Why is it checking st_mode instead of laststatval ? That seems wrong,
> if the last stat() returned -1 then r->finfo.st_mode shouldn't be
> trusted, no?

$r->finfo shouldn't check laststatval, Apache did the stat() for
&r->finfo, which doesn not know about PL_laststatval. r->finfo.st_mode
should always be 0 if the stat() of r->filename failed, see
http_request.c:

/* must set this to zero, some stat()s may have corrupted it
* even if they returned an error.
*/
r->finfo.st_mode = 0;

and http_core.c tests that value:

if (r->finfo.st_mode == 0 || (r->path_info && *r->path_info)) {
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, r,
"File does not exist: %s",r->path_info ?
ap_pstrcat(r->pool, r->filename, r->path_info, NULL)
: r->filename);
return HTTP_NOT_FOUND;
}

i think we're ok to use that test for $r->finfo


cholet at logilune

Jul 25, 2000, 2:45 AM

Post #2 of 3 (1104 views)
Permalink
Re: PL_laststatval [In reply to]

> > I want to fix this bug in r->filename. Currently it does this:
> >
> > CODE:
> > get_set_PVp(r->filename,r->pool);
> > #ifndef WIN32
> > if(items > 1)
> > stat(r->filename, &r->finfo);
> > #endif
> >
> > The return code for stat() is not checked, therefore the stat
> > cache is left at its previous value which doesn't seem right.
> > What I want to do is this:
> > CODE:
> > get_set_PVp(r->filename,r->pool);
> > #ifndef WIN32
> > if(items > 1)
> > - stat(r->filename, &r->finfo);
> > + laststatval = stat(r->filename, &r->finfo);
> > #endif
>
> missing one piece from roger's patch, something like so:
>
> if ((laststatval = stat(...)) < 0) {
> r->finfo.st_mode = 0;
> }
>
> > What bothers me is this code in r->finfo:
> >
> > CODE:
> > statcache = r->finfo;
> > if (r->finfo.st_mode) {
> > laststatval = 0;
> > }
> > else {
> > laststatval = -1;
> > }
> >
> > Why is it checking st_mode instead of laststatval ? That seems wrong,
> > if the last stat() returned -1 then r->finfo.st_mode shouldn't be
> > trusted, no?
>
> $r->finfo shouldn't check laststatval, Apache did the stat() for
> &r->finfo, which doesn not know about PL_laststatval. r->finfo.st_mode
> should always be 0 if the stat() of r->filename failed, see
> http_request.c:
>
> /* must set this to zero, some stat()s may have corrupted it
> * even if they returned an error.
> */
> r->finfo.st_mode = 0;
>
> and http_core.c tests that value:
>
> if (r->finfo.st_mode == 0 || (r->path_info && *r->path_info)) {
> ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, r,
> "File does not exist: %s",r->path_info ?
> ap_pstrcat(r->pool, r->filename, r->path_info, NULL)
> : r->filename);
> return HTTP_NOT_FOUND;
> }
>
> i think we're ok to use that test for $r->finfo

Doug,

Thanks for the insight, it all makes sense now. Therefore the patch I propose
to commit is:

Index: Apache.xs
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/Apache.xs,v
retrieving revision 1.98
diff -u -r1.98 Apache.xs
--- Apache.xs 2000/06/05 18:18:49 1.98
+++ Apache.xs 2000/07/25 09:43:54
@@ -1870,7 +1870,9 @@
get_set_PVp(r->filename,r->pool);
#ifndef WIN32
if(items > 1)
- stat(r->filename, &r->finfo);
+ if ((laststatval = stat(r->filename, &r->finfo)) < 0) {
+ r->finfo.st_mode = 0;
+ }
#endif

OUTPUT:

I'm just double-checking 'cuz I don't want to break anything in
this sensitive area.

Thanks,
--
Eric


dougm at pobox

Jul 25, 2000, 8:57 AM

Post #3 of 3 (1123 views)
Permalink
Re: PL_laststatval [In reply to]

On Tue, 25 Jul 2000, Eric Cholet wrote:

> Doug,
>
> Thanks for the insight, it all makes sense now. Therefore the patch I propose
> to commit is:

looks good, thanks eric!

ModPerl dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.