Added
Link Here
|
1 |
--- lib/OpenSSL.pm.orig |
2 |
+++ lib/OpenSSL.pm |
3 |
@@ -22,6 +22,7 @@ |
4 |
|
5 |
use POSIX; |
6 |
use IPC::Open3; |
7 |
+use IO::Select; |
8 |
use Time::Local; |
9 |
|
10 |
sub new { |
11 |
@@ -41,7 +42,7 @@ |
12 |
close(TEST); |
13 |
|
14 |
# set version (format: e.g. 0.9.7 or 0.9.7a) |
15 |
- if($v =~ /\b(0\.9\.[678][a-z]?)\b/) { |
16 |
+ if($v =~ /\b(0\.9\.[6-9][a-z]?)\b/ || $v =~ /\b(1\.0\.[01][a-z]?)\b/) { |
17 |
$self->{'version'} = $1; |
18 |
} |
19 |
|
20 |
@@ -817,7 +818,7 @@ |
21 |
my $self = shift; |
22 |
my $opts = { @_ }; |
23 |
|
24 |
- my ($tmp, $ext, $ret, $file, $pid, $cmd); |
25 |
+ my ($tmp, $ext, $ret, $file, $pid, $cmd, $cmdout, $cmderr); |
26 |
$file = HELPERS::mktmp($self->{'tmp'}."/data"); |
27 |
|
28 |
$cmd = "$self->{'bin'} $opts->{'cmd'}"; |
29 |
@@ -830,16 +831,7 @@ |
30 |
$cmd .= " -outform $opts->{'outform'}"; |
31 |
} |
32 |
|
33 |
- my($rdfh, $wtfh); |
34 |
- $ext = "$cmd\n\n"; |
35 |
- $pid = open3($wtfh, $rdfh, $rdfh, $cmd); |
36 |
- print $wtfh "$opts->{'data'}\n"; |
37 |
- while(<$rdfh>){ |
38 |
- $ext .= $_; |
39 |
- # print STDERR "DEBUG: cmd ret: $_"; |
40 |
- }; |
41 |
- waitpid($pid, 0); |
42 |
- $ret = $?>>8; |
43 |
+ ($ret, $tmp, $ext) = _run_with_fixed_input($cmd, $opts->{'data'}); |
44 |
|
45 |
if($self->{'broken'}) { |
46 |
if(($ret != 0 && $opts->{'cmd'} ne 'crl') || |
47 |
@@ -859,14 +851,15 @@ |
48 |
} |
49 |
} |
50 |
|
51 |
- open(IN, $file) || do { |
52 |
- my $t = sprintf(_("Can't open file %s: %s"), $file, $!); |
53 |
- GUI::HELPERS::print_warning($t); |
54 |
- return; |
55 |
- }; |
56 |
- $tmp .= $_ while(<IN>); |
57 |
- close(IN); |
58 |
- |
59 |
+ if (-s $file) { # If the file is empty, the payload is in $tmp (via STDOUT of the called process). |
60 |
+ open(IN, $file) || do { |
61 |
+ my $t = sprintf(_("Can't open file %s: %s"), $file, $!); |
62 |
+ GUI::HELPERS::print_warning($t); |
63 |
+ return; |
64 |
+ }; |
65 |
+ $tmp .= $_ while(<IN>); |
66 |
+ close(IN); |
67 |
+ } |
68 |
unlink($file); |
69 |
|
70 |
return($ret, $tmp, $ext); |
71 |
@@ -1076,4 +1069,72 @@ |
72 |
} |
73 |
} |
74 |
|
75 |
+ |
76 |
+=over |
77 |
+ |
78 |
+=item _run_with_fixed_input($cmd, $input) |
79 |
+ |
80 |
+This function runs C<$cmd> and writes the C<$input> to STDIN of the |
81 |
+new process (all at once). |
82 |
+ |
83 |
+While the command runs, all of its output to STDOUT and STDERR is |
84 |
+collected. |
85 |
+ |
86 |
+After the command terminates (closes both STDOUT and STDIN) the |
87 |
+function returns the command's return value as well as everything it |
88 |
+wrote to its STDOUT and STDERR in a list. |
89 |
+ |
90 |
+=back |
91 |
+ |
92 |
+=cut |
93 |
+ |
94 |
+sub _run_with_fixed_input { |
95 |
+ my $cmd = shift; |
96 |
+ my $input = shift; |
97 |
+ |
98 |
+ my ($wtfh, $rdfh, $erfh, $pid, $sel, $ret, $stdout, $stderr); |
99 |
+ $erfh = Symbol::gensym; # Must not be false, otherwise it is lumped together with rdfh |
100 |
+ |
101 |
+ # Run the command |
102 |
+ $pid = open3($wtfh, $rdfh, $erfh, $cmd); |
103 |
+ print $wtfh $input, "\n"; |
104 |
+ |
105 |
+ $stdout = ''; |
106 |
+ $stderr = ''; |
107 |
+ $sel = new IO::Select($rdfh, $erfh); |
108 |
+ while (my @fhs = $sel->can_read()) { |
109 |
+ foreach my $fh (@fhs) { |
110 |
+ if ($fh == $rdfh) { # STDOUT |
111 |
+ my $bytes_read = sysread($fh, my $buf='', 1024); |
112 |
+ if ($bytes_read == -1) { |
113 |
+ warn("Error reading from child's STDOUT: $!\n"); |
114 |
+ $sel->remove($fh); |
115 |
+ } elsif ($bytes_read == 0) { |
116 |
+ # print("Child's STDOUT closed.\n"); |
117 |
+ $sel->remove($fh); |
118 |
+ } else { |
119 |
+ $stdout .= $buf; |
120 |
+ } |
121 |
+ } |
122 |
+ elsif ($fh == $erfh) { # STDERR |
123 |
+ my $bytes_read = sysread($fh, my $buf='', 1024); |
124 |
+ if ($bytes_read == -1) { |
125 |
+ warn("Error reading from child's STDERR: $!\n"); |
126 |
+ $sel->remove($fh); |
127 |
+ } elsif ($bytes_read == 0) { |
128 |
+ # print("Child's STDERR closed.\n"); |
129 |
+ $sel->remove($fh); |
130 |
+ } else { |
131 |
+ $stderr .= $buf; |
132 |
+ } |
133 |
+ } |
134 |
+ } |
135 |
+ } |
136 |
+ |
137 |
+ waitpid($pid, 0); |
138 |
+ $ret = $?>>8; |
139 |
+ |
140 |
+ return ($ret, $stdout, $stderr) |
141 |
+ } |
142 |
+ |
143 |
1 |