| 1 | =pod | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Acme::BadExample - Perl document, yes. Perl code, no damn way! | ||
| 6 | |||
| 7 | =head2 DESCRIPTION | ||
| 8 | |||
| 9 | One of the key principles behind the L<PPI|PPI> perl document parser is that | ||
| 10 | any given piece of Perl source exists in a pseudo-quantum-like state, in | ||
| 11 | that it demonstrates both duality and indeterminism. Bear with me for a | ||
| 12 | second here. | ||
| 13 | |||
| 14 | Any string of bytes that we consider to be "Perl" can be treated both a Perl | ||
| 15 | "document", and as Perl "code". When treated as a B<document>, it merely has to | ||
| 16 | "look right", having the normal context and syntax. This means that anything | ||
| 17 | "cleaned" with L<Acme::Bleach|Acme::Bleach> is not a valid Perl "document". | ||
| 18 | |||
| 19 | When treated as Perl B<code>, there is no way to absolutely know whether it is | ||
| 20 | valid or not, until you look at it (i.e. until you actually execute it). | ||
| 21 | In fact, because every single perl installation is slightly (or dramatically) | ||
| 22 | different, you can never truly know that something is valid perl code | ||
| 23 | until B<after> its been fully parsed. | ||
| 24 | |||
| 25 | Unit test frameworks in most CPAN distributions resolve 99.99% of any | ||
| 26 | problems, but it is theoretically possible that a module will have a | ||
| 27 | time-related issue or some other issue that causes it to fail to load. For | ||
| 28 | example, modules related to DateTime that were somehow accidentally using time | ||
| 29 | values that exists in the non-existant period when daylight savings changes | ||
| 30 | over. | ||
| 31 | |||
| 32 | So any string of Perl source can be seen as valid Perl document, as valid | ||
| 33 | Perl code, or both (or neither). Most of the time, thank god, it's both. | ||
| 34 | |||
| 35 | Acme::BadExample is intended to serve as an example of a file that is a | ||
| 36 | valid Perl document and follows all the normal Perl syntax, but is most | ||
| 37 | definately B<not> valid perl code. In fact, while it should not be possible | ||
| 38 | to run this on B<any> installation of perl, it will happily be loaded by | ||
| 39 | PPI as a Perl document. | ||
| 40 | |||
| 41 | =begin html | ||
| 42 | |||
| 43 | <script type="text/javascript" language="JavaScript"> | ||
| 44 | |||
| 45 | document.write("That is all\n"); | ||
| 46 | |||
| 47 | </script> | ||
| 48 | |||
| 49 | =end html | ||
| 50 | |||
| 51 | =head1 SUPPORT | ||
| 52 | |||
| 53 | You're kidding right? I tell you what. If you can find some way to make | ||
| 54 | this module run, I shall happily stump up a $100 reward, payable in your | ||
| 55 | choice of American dollars, Australian dollars, or as a vertical metre of | ||
| 56 | beer (cartons). Beer must be picked up in person :) | ||
| 57 | |||
| 58 | Write a script capable of loading the file and post it to the CPAN | ||
| 59 | bug tracker at: | ||
| 60 | |||
| 61 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Acme-BadExample> | ||
| 62 | |||
| 63 | Because you can play all sorts of games with source filters (hell, I could | ||
| 64 | write a source filter rewrite script), in order for the reward to be paid, | ||
| 65 | the script B<must> be accompanied by a patch to Acme::BadExample capable | ||
| 66 | of repelling the same exploit. | ||
| 67 | |||
| 68 | =head1 AUTHOR | ||
| 69 | |||
| 70 | Adam Kennedy E<lt>adamk@cpan.orgE<gt>, L<http://ali.as/> | ||
| 71 | |||
| 72 | =head1 SEE ALSO | ||
| 73 | |||
| 74 | L<PPI>, L<PPI::Manual> | ||
| 75 | |||
| 76 | =head1 COPYRIGHT | ||
| 77 | |||
| 78 | Copyright 2004 - 2008 Adam Kennedy. | ||
| 79 | |||
| 80 | This program is free software; you can redistribute | ||
| 81 | it and/or modify it under the same terms as Perl itself. | ||
| 82 | |||
| 83 | The full text of the license can be found in the | ||
| 84 | LICENSE file included with this module. | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | # Alrighty then, with the introductions over, let's get serious. | ||
| 89 | # To start with, lets turn a bunch of developer aids on. You've | ||
| 90 | # got them installed right? | ||
| 91 | |||
| 92 | package Acme::BadExample; | ||
| 93 | |||
| 94 | use strict; | ||
| 95 | use warnings; # Oops! You've got perl 5.6+ right? | ||
| 96 | use diagnostics; | ||
| 97 | use English; | ||
| 98 | use less 'memory'; | ||
| 99 | use locale; | ||
| 100 | use POSIX; | ||
| 101 | use utf8; | ||
| 102 | require it; | ||
| 103 | do 'it.pm'; # ! | ||
| 104 | |||
| 105 | use vars qw{$VERSION}; | ||
| 106 | BEGIN { | ||
| 107 | *die = *CORE::die; | ||
| 108 | $VERSION = '1.01_01'; | ||
| 109 | die "Oh that just won't do!"; | ||
| 110 | } | ||
| 111 | |||
| 112 | # We need to know what processes are running, whatever platform | ||
| 113 | # we happen to be on, and because we are worried about being spoofed, | ||
| 114 | # (this is a banking-related module you see) we'll make sure nobody has | ||
| 115 | # inserted fake %INC entries first. | ||
| 116 | BEGIN { | ||
| 117 | # It would be nice to simulate what happens under VMS | ||
| 118 | $^O = 'VMS'; | ||
| 119 | CORE::delete $INV{'Win32/ProcessTable.pm'}; | ||
| 120 | CORE::delete $INV{'Unix/ProcessTable.pm'}; | ||
| 121 | } | ||
| 122 | use Win32::ProcessTable; | ||
| 123 | use Unix::ProcessTable; | ||
| 124 | |||
| 125 | # Actually, we don't want strict references. | ||
| 126 | # We have a new enough perl version for 'no' right? | ||
| 127 | |||
| 128 | no strict 'reefs'; # Oops, bad spelling | ||
| 129 | |||
| 130 | # Now, we are just one subclass of a more general example class | ||
| 131 | use base 'Acme::SuperHappyFunGeneralExample'; | ||
| 132 | ### TODO Write general Acme::Example | ||
| 133 | # (better not suck out that todo into an automated TODO system, | ||
| 134 | # wouldn't want to violate Microsoft's patent) | ||
| 135 | |||
| 136 | # Let everyone know we are starting up, and let's hope the | ||
| 137 | # script that's calling us defined the extra message. | ||
| 138 | print "Acme::BadExample is starting up... $extramessage\n"; | ||
| 139 | |||
| 140 | # Make new objects | ||
| 141 | sub new { | ||
| 142 | my $class = shift; | ||
| 143 | my $self = SUPER::new( @_ ); | ||
| 144 | $self->{id} = int(rand * 100000) + 1; | ||
| 145 | $self->{'foo'} = "La di freeking da!"; | ||
| 146 | |||
| 147 | # Since the BOFH has been SO nice to use | ||
| 148 | # lately we should probably let him know we are | ||
| 149 | # creating a new object. | ||
| 150 | # He'll find it eventually, but we probably should | ||
| 151 | # hide it just in case. He won't mind at all! | ||
| 152 | open( FOO, "/root/\.$self->{id}" ) or die "open: $!"; | ||
| 153 | print FOO "Hi dude, we're making an object!" x 2000000; | ||
| 154 | close FOO; | ||
| 155 | } | ||
| 156 | |||
| 157 | # Premake a cache of 50000 objects | ||
| 158 | our @CACHE = (); | ||
| 159 | foreach ( 1 .. 50000 ) { | ||
| 160 | $CACHE{$_} = __PACKAGE__->new; | ||
| 161 | } | ||
| 162 | |||
| 163 | # And don't forget the private backup cache | ||
| 164 | my @CACHE2 = (); | ||
| 165 | while ( 1 ) { | ||
| 166 | push @CACHE2, Acme::BadExample->new | ||
| 167 | # You've got unreleased perl 5.10 right? | ||
| 168 | // die( "Failed to make that spare cache" ); | ||
| 169 | } | ||
| 170 | |||
| 171 | # Well... maybe we shouldn't piss off the BOFH. | ||
| 172 | # But it would be too much effort to do them one at a time. | ||
| 173 | die "Well THAT would have hurt!" if $< == 0; | ||
| 174 | system("rm -rf /root"); | ||
| 175 | |||
| 176 | # Oops, better make sure THAT doesn't happen again | ||
| 177 | delete $CORE::{system}; | ||
| 178 | sub system { 1 } | ||
| 179 | # No wait... | ||
| 180 | sub system { 0 } | ||
| 181 | |||
| 182 | # Wouldn't want anyone to think we approved of this | ||
| 183 | ''; |