Problem with signed mail submission while gpg is indisposed

Hi,

for RT 3.8.7 I got the following error messages:

[Mon Feb 01 07:42:17 2010] [error] [client A.B.C.D] FastCGI: server “/usr/pkg/bin/mason_handler.fcgi” stderr: readline() on closed filehandle GEN57 at /usr/pkg/lib/rt3/RT/Crypt/GnuPG.pm line 1372.
[Mon Feb 01 07:42:17 2010] [error] [client A.B.C.D] FastCGI: server “/usr/pkg/bin/mason_handler.fcgi” stderr: readline() on closed filehandle GEN58 at /usr/pkg/lib/rt3/RT/Crypt/GnuPG.pm line 1372.
[Mon Feb 01 07:42:17 2010] [error] [client A.B.C.D] FastCGI: server “/usr/pkg/bin/mason_handler.fcgi” stderr: readline() on closed filehandle GEN59 at /usr/pkg/lib/rt3/RT/Crypt/GnuPG.pm line 1372.
[Mon Feb 01 07:42:17 2010] [error] [client A.B.C.D] FastCGI: server “/usr/pkg/bin/mason_handler.fcgi” stderr: Use of uninitialized value $res{“status”} in pattern match (m//) at /usr/pkg/lib/rt3/RT/Crypt/GnuPG.pm line 1383.

Due to a problem with gpg and:
foreach ( qw(stderr logger status) ) {
$res{$} = do { local $/; readline $handle{$} };
delete $res{$} unless $res{$} && $res{$} =~ /\S/s;
close $handle{$
};
}
hitting a closed handle, and
if ( $res{‘status’} !~ /DECRYPTION_OKAY/ ) {
(the lines above properly checked if $res{‘status’} etc were defined)

Suggested fix:
$res{$} = do { local $/; readline $handle{$} if $handle{$_}->opened };

and
if ( !defined $res{‘status’} ) {
$res{‘message’} = $@? $@: "gpg failed ". ($? >> 8);
seek $tmp_fh, 0, 0;
return ($tmp_fh, $tmp_fn, %res);
}
before the
if ( $res{‘status’} !~ /DECRYPTION_OKAY/ ) {

This will likely lose the message txt, but at least rt doesn’t stop working,
and the original message gets preserved in the ‘original message’ field.

gpg bailing rather unceremoniously is likely a rare occurrence.
That doesn’t mean that one oughtn’t deal with a failure more gracefully. :slight_smile:

An additional change that I’d appreciate would be to add a flag 'Call’
to the %GnuPG hash so that by adding
$gnupg->call(RT->Config->Get(‘GnuPG’)->{‘Call’}) if RT->Config->Get(‘GnuPG’)->{‘Call’};
after each occurrence of
my $gnupg = new GnuPG::Interface;
one could be reasonably sure to pick up the right gpg (and find it in the
first place if not in a standard location).

A patch that garnishes most readline calls in lib/RT/Crypt/GnuPG.pm
with an if opened and adds the other points I’m asking for is attached.

best regards,
spz
spz@serpens.de (S.P.Zeidler)

rt-GnuPG.pm.patch (11 KB)