From: Kazuhiro NISHIYAMA Date: 2008-09-07T12:39:11+09:00 Subject: [ruby-dev:36193] [Bug #466] test_str_crypt(TestM17NComb) failed チケット #466 が更新されました。 (by Kazuhiro NISHIYAMA) 以下のようにconfigureでチェックしてしまうのがいいかと思ったのですが、 どうでしょうか? 影響範囲がよくわからなかったので、実際に値が変わってしまうことがあった darwinの時だけチェックするようなパッチにしてみました。 Index: configure.in =================================================================== --- configure.in (revision 19208) +++ configure.in (working copy) @@ -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 +#include +#include +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: string.c =================================================================== --- string.c (revision 19208) +++ string.c (working copy) @@ -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; ---------------------------------------- http://redmine.ruby-lang.org/issues/show/466 ---------------------------------------- http://redmine.ruby-lang.org