mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
78543725eb
commit
6bf5c34cf2
3 changed files with 41 additions and 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
|
||||
|
|
20
configure.in
20
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;;
|
||||
|
|
15
string.c
15
string.c
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue