summaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2001-09-03 19:50:57 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2001-09-03 19:50:57 +0000
commit85c16d835facb3e1567f0ad453769c0d9a8da60b (patch)
tree18e98ac37b49f61765b436c2fb4fcc0f200c99a7 /pp.c
parent0686c0b8fd853975c64d3472ef479435ba920e0a (diff)
downloadperl-85c16d835facb3e1567f0ad453769c0d9a8da60b.tar.gz
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
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c18
1 files changed, 17 insertions, 1 deletions
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.");