Menu

#2861 perl segmentation fault if callbacks die

perl
open
nobody
perl (81)
5
2018-04-24
2018-04-24
No

When using asynchronous operations with callbacks, these callbacks are assumed not to die. If they do die, the perl process segmentation faults, as illustrated by this test script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/usr/bin/perl -w
use strict;
use SNMP;
my $sess = SNMP::Session->new(
    'DestHost' => 'localhost',
    'Version' => '2c',
    'Community' => 'public',
);
$sess->get( [['ifInOctets', 1]], sub {
    die "an error";
    SNMP::finish();
});
SNMP::MainLoop();

Output:

an error at /home/peter/junk/snmpSegfault-callback-dies.pl line 10.
Segmentation fault

The provided patch (for 5.7.3 and 5.8.pre2) runs callbacks with G_EVAL. If the callbacks fail/die, a warning is issued, but a custom handler can also be set up allowing for custom handling. Here from is the added perldoc:

=head1 Handling errors from SNMP callbacks

Callbacks given to operations such as
C<< $sess->get([['leaf',1]], sub {}) >> should not C<die>. If they do
anyway, by default a warning is issued.  You can however set a global
C<$SNMP::callback_error_handler> handler for custom handling of such
errors:

    $SNMP::callback_error_handler = sub {
        my ($error) = @_;
        printf "Handling error from callback: %s\n", $error;
        # And whatever makes sense for your application...
    };
1 Attachments

Discussion


Log in to post a comment.