From: Nicholas Clark Date: Tue, 16 Feb 2010 16:16:33 +0000 (+0000) Subject: Fix #72850 - reading $! shouldn't SEGV if Strerror(errno) returns NULL. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=be1cf43c8dab9dd236839206d53611f7e7d2d856;p=p5sagit%2Fp5-mst-13.2.git Fix #72850 - reading $! shouldn't SEGV if Strerror(errno) returns NULL. This can happen on some OSes for out of range errno values. The bug was introduced with 0097b436152452e4, which in turn fixed #61976. Test case by Steve Peters. --- diff --git a/mg.c b/mg.c index cc01547..06c899e 100644 --- a/mg.c +++ b/mg.c @@ -1048,7 +1048,8 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg) else #endif sv_setpv(sv, errno ? Strerror(errno) : ""); - SvPOK_on(sv); /* may have got removed during taint processing */ + if (SvPOKp(sv)) + SvPOK_on(sv); /* may have got removed during taint processing */ RESTORE_ERRNO; } diff --git a/t/op/magic.t b/t/op/magic.t index 975be11..3df3e4b 100644 --- a/t/op/magic.t +++ b/t/op/magic.t @@ -12,7 +12,7 @@ BEGIN { use warnings; use Config; -plan (tests => 79); +plan (tests => 80); $Is_MSWin32 = $^O eq 'MSWin32'; $Is_NetWare = $^O eq 'NetWare'; @@ -491,3 +491,9 @@ foreach my $sig (qw(__DIE__ _BOGUS_HOOK KILL THIRSTY)) { is $SIG{$sig}, undef, "$sig is not present"; is delete $SIG{$sig}, undef, "delete of $sig returns undef"; } + +{ + $! = 9999; + is int $!, 9999, q{[perl #72850] Core dump in bleadperl from perl -e '$! = 9999; $a = $!;'}; + +}