[前][次][番号順一覧][スレッド一覧]

ruby-changes:7862

From: nobu <ko1@a...>
Date: Tue, 16 Sep 2008 21:33:56 +0900 (JST)
Subject: [ruby-changes:7862] Ruby:r19383 (trunk): * string.c (rb_str_crypt): orthodox crypt() sees only first two bytes

nobu	2008-09-16 21:33:40 +0900 (Tue, 16 Sep 2008)

  New Revision: 19383

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19383

  Log:
    * string.c (rb_str_crypt): orthodox crypt() sees only first two bytes
      of salt.

  Modified files:
    trunk/ChangeLog
    trunk/string.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19382)
+++ ChangeLog	(revision 19383)
@@ -1,3 +1,8 @@
+Tue Sep 16 21:33:22 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_str_crypt): orthodox crypt() sees only first two bytes
+	  of salt.
+
 Tue Sep 16 19:18:40 2008  Tadayoshi Funaba  <tadf@d...>
 
 	* complex.c (nucomp_marshal_{dump,load}): preserve instance
Index: string.c
===================================================================
--- string.c	(revision 19382)
+++ string.c	(revision 19383)
@@ -5539,7 +5539,7 @@
 static VALUE
 rb_str_each_codepoint(VALUE str)
 {
-    int i, len, n;
+    int len, n;
     unsigned int c;
     const char *ptr, *end;
     rb_encoding *enc;
@@ -6099,30 +6099,27 @@
 {
     extern char *crypt(const char *, const char *);
     VALUE result;
-    const char *s;
+    const char *s, *saltp;
 #ifdef BROKEN_CRYPT
-    VALUE salt_8bit_clean;
-    rb_encoding *enc;
+    char salt_8bit_clean[3];
 #endif
 
     StringValue(salt);
     if (RSTRING_LEN(salt) < 2)
 	rb_raise(rb_eArgError, "salt too short (need >=2 bytes)");
 
-    if (RSTRING_PTR(str)) s = RSTRING_PTR(str);
-    else s = "";
+    s = RSTRING_PTR(str);
+    if (!s) s = "";
+    saltp = RSTRING_PTR(salt);
 #ifdef BROKEN_CRYPT
-    salt_8bit_clean = rb_str_dup(salt);
-    enc = rb_ascii8bit_encoding();
-    str_modifiable(salt_8bit_clean);
-    rb_enc_associate(salt_8bit_clean, enc);
-    salt_8bit_clean = rb_str_tr(salt_8bit_clean,
-                                rb_enc_str_new("\x80-\xFF", 3, enc),
-                                rb_usascii_str_new("\x00-\x7F", 3));
-    result = rb_str_new2(crypt(s, RSTRING_PTR(salt_8bit_clean)));
-#else
-    result = rb_str_new2(crypt(s, RSTRING_PTR(salt)));
+    if (!ISASCII((unsigned char)saltp[0]) || !ISASCII((unsigned char)saltp[1])) {
+	salt_8bit_clean[0] = saltp[0] & 0x7f;
+	salt_8bit_clean[1] = saltp[1] & 0x7f;
+	salt_8bit_clean[2] = '\0';
+	saltp = salt_8bit_clean;
+    }
 #endif
+    result = rb_str_new2(crypt(s, saltp));
     OBJ_INFECT(result, str);
     OBJ_INFECT(result, salt);
     return result;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]