summaryrefslogtreecommitdiff
path: root/t/io/defout.t
diff options
context:
space:
mode:
authorTony Cook <tony@develop-help.com>2023-01-23 15:28:12 +1100
committerTony Cook <tony@develop-help.com>2023-01-25 09:26:27 +1100
commitaf62106ad344b13fde54d2c0d5e7e0d0bab96054 (patch)
treec2f835b80175fdfd0e3ff533e6271dda9a1aeac8 /t/io/defout.t
parentfa1fe46855cd623ff0f787f3025c3c3f14cd57b4 (diff)
downloadperl-af62106ad344b13fde54d2c0d5e7e0d0bab96054.tar.gz
check the IO object exists when writing to IO magic variables
pp_select() ensures that the GV in PL_defoutgv has an IO object when it the default output is set, but can't prevent that GV being cleared afterwards, resulting in a seg fault when the variable is written. To prevent this, check PL_defoutgv has an IO object before trying to write to it. Fixes #20733
Diffstat (limited to 't/io/defout.t')
-rw-r--r--t/io/defout.t16
1 files changed, 15 insertions, 1 deletions
diff --git a/t/io/defout.t b/t/io/defout.t
index aa40666162..2c8af5c80d 100644
--- a/t/io/defout.t
+++ b/t/io/defout.t
@@ -14,7 +14,7 @@ BEGIN {
$|=0; # test.pl makes it 1, and that conflicts with the below.
-plan tests => 16;
+plan tests => 22;
my $stdout = *STDOUT;
@@ -48,6 +48,20 @@ $- = 1; pass '$- = 1';
$% = 1; pass '$% = 1';
$| = 1; pass '$| = 1';
+# test a NULLed GV
+my $t = tempfile;
+open FOO, ">", $t or die;
+select(FOO);
+my $io = *FOO{IO};
+*FOO = 0;
+$^ = 1; pass 'empty GV: $^ = 1';
+$~ = 1; pass 'empty GV: $~ = 1';
+$= = 1; pass 'empty GV: $= = 1';
+$- = 1; pass 'empty GV: $- = 1';
+$% = 1; pass 'empty GV: $% = 1';
+$| = 1; pass 'empty GV: $| = 1';
+close $io;
+
# Switch to STDERR for this test, so we do not lose our test output
my $stderr = *STDERR;
select($stderr);