diff options
author | kazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-07 08:57:53 +0000 |
---|---|---|
committer | kazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-07 08:57:53 +0000 |
commit | 6bf5c34cf20002491423ca69dc3b0d037afaaefd (patch) | |
tree | 376718743cf772a020cf081cde1eb0a65bf8276c | |
parent | 78543725ebbb47a1132c93e629af91891d8258ff (diff) | |
download | bundler-6bf5c34cf20002491423ca69dc3b0d037afaaefd.tar.gz |
* configure.in: Mac OS X's crypt(2) is broken with invalid salt.
[ruby-dev:35899]
* string.c (rb_str_crypt): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | configure.in | 20 | ||||
-rw-r--r-- | string.c | 15 |
3 files changed, 41 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Sun Sep 7 17:54:45 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com> + + * 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@fsij.org> * tool/transcode-tblgen.rb: o4 is usable only if the first byte is diff --git a/configure.in b/configure.in index 26c2e00aca..3e1130d050 100644 --- a/configure.in +++ b/configure.in @@ -523,6 +523,26 @@ darwin*) LIBS="-lobjc $LIBS" 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;; @@ -5862,6 +5862,10 @@ rb_str_crypt(VALUE str, VALUE salt) 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 @@ rb_str_crypt(VALUE str, VALUE salt) 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; |