perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe M. Chiasson" <go...@cpan.org>
Subject [mp1 bug] mp_preload_module() bustage
Date Wed, 11 Jun 2003 10:23:19 GMT
After squirrelling down some source code, tracking something
completely unrelated, I came to notice something I believe
is busted.

mp_preload_module(char **name) gets called in perl_config.c
whenever processing a directive like Perl*Handler. Like this bit:

CHAR_P perl_cmd_push_handlers(char *hook, PERL_CMD_TYPE **cmd, char
*arg, pool *p)
{ 
    SV *sva;
    /* XXX ---> */ mp_preload_module(&arg);
    sva = newSVpv(arg,0); 

[...]

static void mp_preload_module(char **name)
{
    if(ind(*name, ' ') >= 0) return;
    if(**name == '-' && ++*name) return;
    if(**name == '+') ++*name;
    else if(!PERL_AUTOPRELOAD) return;
    if(!PERL_RUNNING()) return;

    if(!perl_module_is_loaded(*name)) { 
	MP_TRACE_d(fprintf(stderr, 
			   "mod_perl: attempting to pre-load module `%s'\n", 
			   *name));
	perl_require_module(*name,NULL);
    }
}

The extra logic at the top of mp_preload_module fixes up the module
name when calling PerlLogHandler (+|-)My::Handler.

Problem happens when you do either:

PerlLogHandler My::Module->somehandler
or
PerlLogHandler $My::Obj->somehandler

Each of those 2 cases will fall through to:
perl_require_module("My::Module->somehandler", NULL);
or
perl_require_module("$My::Obj->somehandler", NULL);

And that does little more than

eval "require My::Module->somehandler";

or

eval "require $My::Obj->somehandler";

In both cases, you have multiple problems...

First of them is that My::Module->somehandler gets called on startup (or
once per request if in a .htaccess) without a valid $r as argument.

Second one, the require call itself will most likely fail, trying to
require the value of Apache::OK.

I propose to fix mp_preload_module to be a bit smarter and skip those
odd cases... 

But I wonder how come this issue hasn't been reported already? Am I
missing something terribly simple here?

Gozer out.

-- 
-- -----------------------------------------------------------------------------
Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5 (122FF51B/C634E37B)
http://gozer.ectoplasm.org/    F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3 A5A5
Q: It is impossible to make anything foolproof because fools are so ingenious.
perl -e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}'

Mime
View raw message