From 85c16d835facb3e1567f0ad453769c0d9a8da60b Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi Date: Mon, 3 Sep 2001 19:50:57 +0000 Subject: Make crypt() do something more sane for Unicode (take crypt() of the low eight bits of the characters, instead of taking crypt() of the UTF-8 of the scalar); add a test for crypt(). p4raw-id: //depot/perl@11852 --- pp.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'pp.c') diff --git a/pp.c b/pp.c index 5538cf47eb..8b09a52042 100644 --- a/pp.c +++ b/pp.c @@ -3095,12 +3095,28 @@ PP(pp_crypt) dSP; dTARGET; dPOPTOPssrl; STRLEN n_a; #ifdef HAS_CRYPT - char *tmps = SvPV(left, 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. */ + char *s = tmps; + char *send = tmps + len; + STRLEN i = 0; + Newz(688, t, len, char); + while (s < send) { + t[i++] = utf8_to_uvchr((U8*)s, 0) & 0xFF; + s += UTF8SKIP(s); + } + tmps = t; + } #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."); -- cgit v1.2.1