| 1 | package Beekeeper::AnyEvent; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | our $VERSION = '0.09'; | ||
| 7 | |||
| 8 | use AnyEvent; | ||
| 9 | use AnyEvent::Socket; | ||
| 10 | |||
| 11 | |||
| 12 | USE_PERL_BACKEND: { | ||
| 13 | |||
| 14 | # Prefer AnyEvent perl backend over default EV, as it is fast enough | ||
| 15 | # and it does not ignore exceptions thrown from within callbacks | ||
| 16 | |||
| 17 | $ENV{'PERL_ANYEVENT_MODEL'} ||= 'Perl' unless $AnyEvent::MODEL; | ||
| 18 | } | ||
| 19 | |||
| 20 | UNTAINT_IP_ADDR: { | ||
| 21 | |||
| 22 | no strict 'refs'; | ||
| 23 | no warnings 'redefine'; | ||
| 24 | |||
| 25 | # Addresses resolved by AnyEvent::DNS are tainted, causing an "Insecure | ||
| 26 | # dependency in connect" error when running with taint mode enabled. | ||
| 27 | # These addresses can be blindly untainted before being passed to parse_ipv4 | ||
| 28 | # and parse_ipv6 because these functions validate addresses properly | ||
| 29 | |||
| 30 | my $parse_ipv4 = \&{'AnyEvent::Socket::parse_ipv4'}; | ||
| 31 | *{'AnyEvent::Socket::parse_ipv4'} = sub ($) { | ||
| 32 | ($_[0]) = $_[0] =~ m/(.*)/s; # untaint addr | ||
| 33 | $parse_ipv4->(@_); | ||
| 34 | }; | ||
| 35 | |||
| 36 | my $parse_ipv6 = \&{'AnyEvent::Socket::parse_ipv6'}; | ||
| 37 | *{'AnyEvent::Socket::parse_ipv6'} = sub ($) { | ||
| 38 | ($_[0]) = $_[0] =~ m/(.*)/s; # untaint addr | ||
| 39 | $parse_ipv6->(@_); | ||
| 40 | }; | ||
| 41 | } | ||
| 42 | |||
| 43 | 1; | ||
| 44 | |||
| 45 | __END__ |