Skip to content

Commit a1b60c8

Browse files
mauketonycoz
authored andcommitted
make do "a\0b" fail silently instead of throwing (RT #129928)
Also remove the label/goto from CLEAR_ERRSV because labels have function scope, which means you couldn't use CLEAR_ERRSV more than once per function without getting a "duplicate label" error.
1 parent 4a59181 commit a1b60c8

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

perl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,14 +1280,13 @@ EXTERN_C char *crypt(const char *, const char *);
12801280
#define CLEAR_ERRSV() STMT_START { \
12811281
SV ** const svp = &GvSV(PL_errgv); \
12821282
if (!*svp) { \
1283-
goto clresv_newemptypv; \
1283+
*svp = newSVpvs(""); \
12841284
} else if (SvREADONLY(*svp)) { \
12851285
SvREFCNT_dec_NN(*svp); \
1286-
clresv_newemptypv: \
12871286
*svp = newSVpvs(""); \
12881287
} else { \
12891288
SV *const errsv = *svp; \
1290-
SvPVCLEAR(errsv); \
1289+
SvPVCLEAR(errsv); \
12911290
SvPOK_only(errsv); \
12921291
if (SvMAGICAL(errsv)) { \
12931292
mg_free(errsv); \

pp_ctl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3692,6 +3692,10 @@ S_require_file(pTHX_ SV *const sv)
36923692
DIE(aTHX_ "Missing or undefined argument to require");
36933693

36943694
if (!IS_SAFE_PATHNAME(name, len, "require")) {
3695+
if (PL_op->op_type != OP_REQUIRE) {
3696+
CLEAR_ERRSV();
3697+
RETPUSHUNDEF;
3698+
}
36953699
DIE(aTHX_ "Can't locate %s: %s",
36963700
pv_escape(newSVpvs_flags("",SVs_TEMP),name,len,len*2,
36973701
NULL, SvUTF8(sv)?PERL_PV_ESCAPE_UNI:0),

t/op/require_errors.t

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ BEGIN {
99
use strict;
1010
use warnings;
1111

12-
plan(tests => 20);
12+
plan(tests => 23);
1313

1414
my $nonfile = tempfile();
1515

@@ -120,11 +120,21 @@ SKIP: {
120120
# fail and print the full filename
121121
eval { no warnings 'syscalls'; require "strict.pm\0invalid"; };
122122
like $@, qr/^Can't locate strict\.pm\\0invalid: /, 'require nul check [perl #117265]';
123-
eval { no warnings 'syscalls'; do "strict.pm\0invalid"; };
124-
like $@, qr/^Can't locate strict\.pm\\0invalid: /, 'do nul check';
125123
{
126124
my $WARN;
127125
local $SIG{__WARN__} = sub { $WARN = shift };
126+
{
127+
my $ret = do "strict.pm\0invalid";
128+
my $exc = $@;
129+
my $err = $!;
130+
is $ret, undef, 'do nulstring returns undef';
131+
is $exc, '', 'do nulstring clears $@';
132+
$! = $err;
133+
ok $!{ENOENT}, 'do nulstring fails with ENOENT';
134+
like $WARN, qr{^Invalid \\0 character in pathname for require: strict\.pm\\0invalid at }, 'do nulstring warning';
135+
}
136+
137+
$WARN = '';
128138
eval { require "strict.pm\0invalid"; };
129139
like $WARN, qr{^Invalid \\0 character in pathname for require: strict\.pm\\0invalid at }, 'nul warning';
130140
like $@, qr{^Can't locate strict\.pm\\0invalid: }, 'nul error';

0 commit comments

Comments
 (0)