Skip to content

Commit 08f800f

Browse files
author
Father Chrysostomos
committed
[perl #128182] Fix crash with require $nonstring
If something other than a plain string (e.g. a reference or typeglob) whose stringified form contains a null character is passed to require() or do(), it crashes, as of v5.19.3-130-gc8028aa, because the code in question that handles the error tries to read fields of the scalar that are only valid if it is a string internally.
1 parent 482e441 commit 08f800f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pp_ctl.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3686,8 +3686,8 @@ S_require_file(pTHX_ SV *const sv)
36863686

36873687
if (!IS_SAFE_PATHNAME(name, len, "require")) {
36883688
DIE(aTHX_ "Can't locate %s: %s",
3689-
pv_escape(newSVpvs_flags("",SVs_TEMP),SvPVX(sv),SvCUR(sv),
3690-
SvCUR(sv)*2,NULL, SvUTF8(sv)?PERL_PV_ESCAPE_UNI:0),
3689+
pv_escape(newSVpvs_flags("",SVs_TEMP),name,len,len*2,
3690+
NULL, SvUTF8(sv)?PERL_PV_ESCAPE_UNI:0),
36913691
Strerror(ENOENT));
36923692
}
36933693
TAINT_PROPER("require");

t/op/require_errors.t

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ BEGIN {
88
use strict;
99
use warnings;
1010

11-
plan(tests => 18);
11+
plan(tests => 20);
1212

1313
my $nonfile = tempfile();
1414

@@ -139,3 +139,11 @@ like $@, qr/^Can't locate strict\.pm\\0invalid: /, 'do nul check';
139139
eval "require strict\0::invalid;";
140140
like $@, qr/^syntax error at \(eval \d+\) line 1/, 'parse error with \0 in barewords module names';
141141

142+
# Refs and globs that stringify with embedded nulls
143+
# These crashed from 5.20 to 5.24 [perl #128182].
144+
eval { no warnings 'syscalls'; require eval "qr/\0/" };
145+
like $@, qr/^Can't locate \(\?\^:\\0\):/,
146+
'require ref that stringifies with embedded null';
147+
eval { no strict; no warnings 'syscalls'; require *{"\0a"} };
148+
like $@, qr/^Can't locate \*main::\\0a:/,
149+
'require ref that stringifies with embedded null';

0 commit comments

Comments
 (0)