BigDeath.pm untested

filter: Statementstmt 0.0% 0 / 71 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 103 CC 8 SCAR 36.1
CC
8
Cov
0%
bigdeath
56.0
display_value
6.0
BEGIN
2.0
CRAP 37.1
1  
2 # Copyright (C) 1996, David Muir Sharnoff
3  
4 #
5 # This is not a package.
6 #
7 # use require to get at it if you have to.
8 #
9  
10 use vars qw($mailserver);
11  
12 sub bigdeath
13 {
14 my ($perlerr, $syserr, $bomb, $out,
15 $envr, $query, $pwd, $zero,
16 $argvr, $debug, $mailto) = @_;
17  
18 local $SIG{__DIE__} = undef;
19 my $cout = $out;
20 $cout =~ s/\</&lt;/g;
21 $cout =~ s/\>/&gt;/g;
22  
23 $mailto = getpwuid($<)
24 unless $mailto;
25  
26 print <<"";
27 Content-type: text/html
28 \n
29 <html>
30 <head>
31 <title>Error!</title>
32 </head>
33 <body>
34 The dynamic web page that you just tried to
35 access has failed. The exact error that it
36 failed with was:
37 <xmp>
38 $bomb
39 </xmp>
40 In addition the following may be of interest:
41 <xmp>
42 \$\@ = $perlerr
43 \$! = $syserr
44 </xmp>
45 There is probably no need to report this error because
46 email has been sent to $mailto with the information below.
47 <p>
48 Had this CGI run completion, the following
49 would have been output (collected so far):
50 <ul>
51 <pre><tt>
52 $cout
53 </tt></pre>
54 </ul>
55  
56  
57 require Net::SMTP;
58 my $smtp = Net::SMTP->new($mailserver || 'localhost');
59  
60 $smtp->mail($mailto);
61 $smtp->to($mailto);
62 $smtp->data();
63  
64 my $remoteuser = $ENV{'REMOTE_USER'} || 'unknown';
65 my $remotehost = $ENV{'REMOTE_ADDR'} || 'unknown';
66  
67 $0 =~ m'([^/]+)$';
68 my $sn = $1 || $0;
69  
70 $smtp->datasend(<<"");
71 To: $mailto
72 From: $remoteuser\@$remotehost
73 Subject: Perl script $sn bombed
74 \n
75 Perl script $0 bombed.
76 \n
77 Bomb code:
78 $bomb
79 \n
80 \$\@ = $perlerr
81 \$! = $syserr
82 \n
83 Debugging info:
84 $debug
85 \n
86  
87 my $qs = '';
88 if (defined $query) {
89 if ($envr->{'REQUEST_METHOD'} =~ /^P/) {
90 $qs = $query->query_string();
91 }
92 }
93  
94 my $e ='';
95 for (keys %e) {
96 my $x = $_;
97 my $y = $envr->{$x};
98 $x =~ s/'/'"'"'/g;
99 $y =~ s/'/'"'"'/g;
100 $e .= "\\\n\t'$x'='$y'";
101 }
102 for ($qs, @$argvr, $zero, $pwd) {
103 s/'/'"'"'/g;
104 }
105 my $ne;
106  
107  
108 my $x = '';
109  
110 if (defined $query) {
111 $x .= "CGI variables:\n\n";
112  
113 my $name;
114 for $name ($query->param()) {
115 my @values = $query->param($name);
116  
117 if (@values > 1) {
118 $x .= "\t$name\n";
119 my $v;
120 for $v (@values) {
121 $x .= display_value($smtp, $v, "\n");
122 }
123 } else {
124 $x .= "\t" . $name . display_value($smtp, $values[0]);
125 }
126 }
127 }
128  
129 $x .= <<"";
130 \n
131 Repeat with:
132 \n
133 /bin/sh <<'END'
134 #!/bin/sh
135 cd '$pwd'
136 echo '$qs' | env - $e $zero @$argvr
137 exit $?
138 'END'
139 \n
140  
141  
142  
143 $smtp->datasend($x);
144 $smtp->datasend("\n\noutput so far:\n$out\n");
145 $smtp->dataend();
146 $smtp->quit();
147 print "<xmp>$x</xmp></body></html>\n";
148  
149 sub display_value
150 {
151 my($smtp, $value, $nl) = @_;
152 my @lines;
153 my $x = '';
154  
155 @lines = split("\n", $value);
156  
157 for (@lines) {
158 s/\r$//;
159 s/\r/\\r/g;
160 s/\f/\\f/g;
161 s/([\0-\37\177-\200])/sprintf("\\x%02x",ord($1))/eg;
162 }
163  
164 if (@lines > 1) {
165 $smtp->datasend("$nl\t\t---- begin\n");
166 my $line;
167 for $line (@lines) {
168 $x .= "\t$line\n";
169 }
170 $x .= "\t\t----- end\n";
171 } else {
172 $x .= "$nl\t\t'$lines[0]'\n";
173 }
174 return $x;
175 }
176  
177 }
178  
179 1;
180