rlauer6 / perl-amazon-s3

A portable client library for working with and managing Amazon S3 buckets and keys.
http://search.cpan.org/dist/Amazon-S3/
2 stars 7 forks source link

Fixed a bug where encryption was impossible in special cases #17

Closed YuseiUeno closed 5 months ago

YuseiUeno commented 5 months ago

Fix catch not expected error bug

If not execute eval then not update $EVAL_ERROR. And _encrypt is not encrypt if existing $EVAL_ERROR and $encryption_key.

$EVAL_ERROR have to check when immediately after eval.

use Amazon::S3;
sub s3 {
 Amazon::S3->new(
    {   aws_access_key_id     => 'xxx',
        aws_secret_access_key => 'yyy',
        retry                 => 1
    }
  );
}

my $s3;
$s3 = s3(); # no problem when `$encryption_key` isn't defined
eval { die 'something...' }; # $EVAL_ERROR updated
$s3 = s3(); # not encrypt AWS keys 

use Test2::V0;
is $s3->aws_access_key_id, 'xxx';
is $s3->aws_secret_access_key, 'yyy';
done_testing;
YuseiUeno commented 5 months ago

[NOTE] If defined $encryption_key then eval is not executed. And $EVAL_ERROR is not updated.

https://github.com/rlauer6/perl-amazon-s3/blob/c0e4a37acd6f7de7eebfe7b595d340d51fc03e16/src/main/perl/lib/Amazon/S3.pm.in#L197-L206

Therefore, encryption will not work if $EVAL_ERROR is present, regardless of whether it was updated it in Amazon::S3 or not.

https://github.com/rlauer6/perl-amazon-s3/blob/c0e4a37acd6f7de7eebfe7b595d340d51fc03e16/src/main/perl/lib/Amazon/S3.pm.in#L208-L210