summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-01 06:58:21 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-01 06:58:21 +0000
commita8bfa9bdf1d203c8cf6c4515ea74aaaca5584f9a (patch)
treed85a22c486d9a20e06c02db30ee66917e0bad7e6 /string.c
parent1258bc559b23c2075b8758484736674d0dab8b0d (diff)
use system crypt
* configure.in: revert r55237. replace crypt, not crypt_r, and check if crypt is broken more. * missing/crypt.c: move crypt_r.c * string.c (rb_str_crypt): use crypt_r if provided by the system. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/string.c b/string.c
index 7c2b597711..711fd9c39e 100644
--- a/string.c
+++ b/string.c
@@ -29,7 +29,9 @@
#include <unistd.h>
#endif
+#ifdef HAVE_CRYPT_R
#include <crypt.h>
+#endif
#define STRING_ENUMERATORS_WANTARRAY 0 /* next major */
@@ -8375,10 +8377,17 @@ rb_str_oct(VALUE str)
static VALUE
rb_str_crypt(VALUE str, VALUE salt)
{
+#ifdef HAVE_CRYPT_R
struct crypt_data data;
+#else
+ extern char *crypt(const char *, const char *);
+#endif
VALUE result;
const char *s, *saltp;
char *res;
+#ifdef BROKEN_CRYPT
+ char salt_8bit_clean[3];
+#endif
StringValue(salt);
mustnot_wchar(str);
@@ -8391,8 +8400,20 @@ rb_str_crypt(VALUE str, VALUE salt)
s = StringValueCStr(str);
saltp = RSTRING_PTR(salt);
if (!saltp[0] || !saltp[1]) goto short_salt;
+#ifdef BROKEN_CRYPT
+ 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
+#ifdef HAVE_CRYPT_R
data.initialized = 0;
res = crypt_r(s, saltp, &data);
+#else
+ res = crypt(s, saltp);
+#endif
if (!res) {
rb_sys_fail("crypt");
}