summaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2002-01-13 18:27:00 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2002-01-13 18:27:00 +0000
commitf2791508ba1ad17a1652fe09ecc58a5c83cae5d7 (patch)
tree4df0b708eb2cfa4ed96c94bd2fb18aba2f07ed8f /pp.c
parent5df7693a57e747d288ae1a7594a516d57bfaf895 (diff)
downloadperl-f2791508ba1ad17a1652fe09ecc58a5c83cae5d7.tar.gz
Make the crypt() pickier: if downgrading doesn't work,
croak. p4raw-id: //depot/perl@14244
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/pp.c b/pp.c
index 319adafc7e..0d7f75bbd3 100644
--- a/pp.c
+++ b/pp.c
@@ -3178,26 +3178,22 @@ PP(pp_crypt)
STRLEN n_a;
STRLEN len;
char *tmps = SvPV(left, len);
- char *t = 0;
if (DO_UTF8(left)) {
- /* If Unicode take the crypt() of the low 8 bits of
- * the characters of the string. Yes, we made this up. */
- char *s = tmps;
- char *send = tmps + len;
- STRLEN i = 0;
- Newz(688, t, len + 1, char);
- while (s < send) {
- t[i++] = utf8_to_uvchr((U8*)s, 0) & 0xFF;
- s += UTF8SKIP(s);
- }
- tmps = t;
+ /* If Unicode, try to dowgrade.
+ * If not possible, croak.
+ * Yes, we made this up. */
+ SV* tsv = sv_2mortal(newSVsv(left));
+
+ SvUTF8_on(tsv);
+ if (!sv_utf8_downgrade(tsv, FALSE))
+ Perl_croak(aTHX_ "Wide character in crypt");
+ tmps = SvPVX(tsv);
}
# ifdef FCRYPT
sv_setpv(TARG, fcrypt(tmps, SvPV(right, n_a)));
# else
sv_setpv(TARG, PerlProc_crypt(tmps, SvPV(right, n_a)));
# endif
- Safefree(t);
#else
DIE(aTHX_
"The crypt() function is unimplemented due to excessive paranoia.");