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

ruby-changes:7692

From: kazu <ko1@a...>
Date: Sun, 7 Sep 2008 17:58:19 +0900 (JST)
Subject: [ruby-changes:7692] Ruby:r19213 (trunk): * configure.in: Mac OS X's crypt(2) is broken with invalid salt.

kazu	2008-09-07 17:57:53 +0900 (Sun, 07 Sep 2008)

  New Revision: 19213

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

  Log:
    * configure.in: Mac OS X's crypt(2) is broken with invalid salt.
      [ruby-dev:35899]
    * string.c (rb_str_crypt): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/configure.in
    trunk/string.c

Index: configure.in
===================================================================
--- configure.in	(revision 19212)
+++ configure.in	(revision 19213)
@@ -523,6 +523,26 @@
 		    AC_DEFINE(BROKEN_SETREUID, 1)
 		    AC_DEFINE(BROKEN_SETREGID, 1)
 		    ])
+		ac_cv_lib_crypt_crypt=no
+                AC_CACHE_CHECK(for broken crypt with 8bit chars, rb_cv_broken_crypt,
+                    [AC_TRY_RUN([
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+int
+main()
+{
+   char buf[256];
+   strcpy(buf, crypt("", "\xE0\xA0"));
+   return strcmp(buf, crypt("", "\xE0\xA0"));
+}
+],
+	            rb_cv_broken_crypt=no,
+	            rb_cv_broken_crypt=yes,
+	            rb_cv_broken_crypt=yes)])
+                if test "$rb_cv_broken_crypt" = yes; then
+                  AC_DEFINE(BROKEN_CRYPT, 1)
+                fi
 		;;
 hpux*)		LIBS="-lm $LIBS"
 		ac_cv_c_inline=no;;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19212)
+++ ChangeLog	(revision 19213)
@@ -1,3 +1,9 @@
+Sun Sep  7 17:54:45 2008  Kazuhiro NISHIYAMA  <zn@m...>
+
+	* configure.in: Mac OS X's crypt(2) is broken with invalid salt.
+	  [ruby-dev:35899]
+	* string.c (rb_str_crypt): ditto.
+
 Sun Sep  7 17:29:49 2008  Tanaka Akira  <akr@f...>
 
 	* tool/transcode-tblgen.rb: o4 is usable only if the first byte is
Index: string.c
===================================================================
--- string.c	(revision 19212)
+++ string.c	(revision 19213)
@@ -5862,6 +5862,10 @@
     extern char *crypt(const char *, const char *);
     VALUE result;
     const char *s;
+#ifdef BROKEN_CRYPT
+    VALUE salt_8bit_clean;
+    rb_encoding *enc;
+#endif
 
     StringValue(salt);
     if (RSTRING_LEN(salt) < 2)
@@ -5869,7 +5873,18 @@
 
     if (RSTRING_PTR(str)) s = RSTRING_PTR(str);
     else s = "";
+#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)));
+#endif
     OBJ_INFECT(result, str);
     OBJ_INFECT(result, salt);
     return result;

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

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