Most code which attempts to find the version number of a given module either uses a naive regex, uses "eval" on the version line, or loads the module and calls $module->VERSION.
I'm writing Module::SafeVersion which attempts to do this correctly, but it may never get released. I'm employing a combination approach of using a rather complicated regex along with some "cleanup" code to handle the majority of cases. Currently it properly extracts about 98% of the versions of modules installed on my laptop. However, the special cases are significant and I can't ignore them.
I can try to continually expand the regex and the cleanup code, but I'm sadly beginning to think that what needs to be done is to build in special cases for those modules which have jumped through ridiculous hoops to generate their version numbers. Let's look at some examples:
# From SOAP::Lite $VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_60-publ +ic $ =~ /-(\d+)_([\d_]+)/) # From SQL::Abstract $VERSION = do { my @r=(q$Revision: 1.20 $=~/\d+/g); sprintf "%d."."%02 +d"x$#r,@r }; # From CPAN my $VERSION = sprintf "%.2f", substr(q$Rev: 245 $,4)/100;
(It should also be pointed out that there are plenty of problems with this approach, too. Particulary since it will never be 100% successful).
Schwern argued that this entire module is the wrong approach. Specifically, if eval'ing a version string is a problem, this implies that you already have bad code on your box and the version string is the least of your problems. PAUSE apparently runs in a chroot jail, so the only folks likely to be bitten by a version string attack would be smoke testers. Thus, if I have code on my box, it should automatically be viewed as trusted. Thoughts?
Cheers,
Ovid
New address of my CGI Course.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Is Module::SafeVersion a Waste of Time?
by itub (Priest) on Apr 24, 2006 at 20:18 UTC | |
Re: Is Module::SafeVersion a Waste of Time?
by dragonchild (Archbishop) on Apr 25, 2006 at 01:20 UTC | |
Re: Is Module::SafeVersion a Waste of Time?
by BrowserUk (Patriarch) on Apr 25, 2006 at 10:23 UTC | |
Re: Is Module::SafeVersion a Waste of Time?
by demerphq (Chancellor) on Apr 25, 2006 at 09:07 UTC | |
by Ovid (Cardinal) on Apr 25, 2006 at 09:27 UTC | |
by demerphq (Chancellor) on Apr 25, 2006 at 10:18 UTC |