Skip to content

Commit

Permalink
Don't taint $x in C<$x = ($tainted =~ /(\w+)/)>
Browse files Browse the repository at this point in the history
  • Loading branch information
Chip Salzenberg authored and Chip Salzenberg committed Feb 21, 1997
1 parent 8bc0c6b commit 9212bbb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pp_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ PP(pp_substcont)
SV *targ = cx->sb_targ;
sv_catpvn(dstr, s, cx->sb_strend - s);

TAINT_IF(cx->sb_rxtainted || rx->exec_tainted);

(void)SvOOK_off(targ);
Safefree(SvPVX(targ));
SvPVX(targ) = SvPVX(dstr);
Expand All @@ -133,8 +135,7 @@ PP(pp_substcont)

(void)SvPOK_only(targ);
SvSETMAGIC(targ);
if (cx->sb_rxtainted)
SvTAINTED_on(targ);
SvTAINT(targ);
PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
LEAVE_SCOPE(cx->sb_oldsave);
POPSUBST(cx);
Expand Down
19 changes: 14 additions & 5 deletions pp_hot.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ PP(pp_match)
strend = s + len;
if (!s)
DIE("panic: do_match");
TAINT_NOT;

if (pm->op_pmflags & PMf_USED) {
if (gimme == G_ARRAY)
Expand Down Expand Up @@ -868,10 +869,10 @@ PP(pp_match)
/*NOTREACHED*/

gotcha:
TAINT_IF(rx->exec_tainted);
if (gimme == G_ARRAY) {
I32 iters, i, len;

TAINT_IF(rx->exec_tainted);
iters = rx->nparens;
if (global && !iters)
i = 1;
Expand Down Expand Up @@ -919,6 +920,7 @@ PP(pp_match)
}

yup:
TAINT_IF(rx->exec_tainted);
++BmUSEFUL(pm->op_pmshort);
curpm = pm;
if (pm->op_pmflags & PMf_ONCE)
Expand Down Expand Up @@ -949,6 +951,7 @@ PP(pp_match)
++BmUSEFUL(pm->op_pmshort);

ret_no:
TAINT_IF(rx->exec_tainted); /* /\W/ */
LEAVE_SCOPE(oldsave);
if (gimme == G_ARRAY)
RETURN;
Expand Down Expand Up @@ -1396,6 +1399,7 @@ PP(pp_subst)
s = SvPV(TARG, len);
if (!SvPOKp(TARG) || SvREADONLY(TARG) || (SvTYPE(TARG) == SVt_PVGV))
force_on_match = 1;
TAINT_NOT;

force_it:
if (!pm || !s)
Expand Down Expand Up @@ -1456,6 +1460,7 @@ PP(pp_subst)
if (c && clen <= rx->minlen) {
if (! pregexec(rx, s, strend, orig, 0,
SvSCREAM(TARG) ? TARG : Nullsv, safebase)) {
TAINT_IF(rx->exec_tainted);
PUSHs(&sv_no);
LEAVE_SCOPE(oldsave);
RETURN;
Expand Down Expand Up @@ -1507,6 +1512,7 @@ PP(pp_subst)
else {
sv_chop(TARG, d);
}
TAINT_IF(rxtainted);
PUSHs(&sv_yes);
}
else {
Expand Down Expand Up @@ -1534,12 +1540,12 @@ PP(pp_subst)
SvCUR_set(TARG, d - SvPVX(TARG) + i);
Move(s, d, i+1, char); /* include the NUL */
}
TAINT_IF(rxtainted);
PUSHs(sv_2mortal(newSViv((I32)iters)));
}
(void)SvPOK_only(TARG);
SvSETMAGIC(TARG);
if (rxtainted)
SvTAINTED_on(TARG);
SvTAINT(TARG);
LEAVE_SCOPE(oldsave);
RETURN;
}
Expand Down Expand Up @@ -1582,6 +1588,8 @@ PP(pp_subst)
} while (pregexec(rx, s, strend, orig, s == m, Nullsv, safebase));
sv_catpvn(dstr, s, strend - s);

TAINT_IF(rxtainted);

(void)SvOOK_off(TARG);
Safefree(SvPVX(TARG));
SvPVX(TARG) = SvPVX(dstr);
Expand All @@ -1592,12 +1600,13 @@ PP(pp_subst)

(void)SvPOK_only(TARG);
SvSETMAGIC(TARG);
if (rxtainted)
SvTAINTED_on(TARG);
SvTAINT(TARG);
PUSHs(sv_2mortal(newSViv((I32)iters)));
LEAVE_SCOPE(oldsave);
RETURN;
}

TAINT_IF(rx->exec_tainted);
PUSHs(&sv_no);
LEAVE_SCOPE(oldsave);
RETURN;
Expand Down

0 comments on commit 9212bbb

Please sign in to comment.