From 3c31685e1117e93ef7186feecfdea665df3cfb66 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 1 Jun 2016 00:48:08 +0000 Subject: [PATCH] use crypt_r * string.c (rb_str_crypt): use reentrant crypt_r. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ common.mk | 2 +- configure.in | 40 ++++------------------------------ missing/{crypt.c => crypt_r.c} | 0 string.c | 18 +++++---------- 5 files changed, 14 insertions(+), 50 deletions(-) rename missing/{crypt.c => crypt_r.c} (100%) diff --git a/ChangeLog b/ChangeLog index 0ac5e4c3f6..ecd49d36dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Wed Jun 1 09:48:06 2016 Nobuyoshi Nakada + + * string.c (rb_str_crypt): use reentrant crypt_r. + Wed Jun 1 09:37:26 2016 NAKAMURA Usaku * missing/crypt.c (des_setkey): void function never returns any value. diff --git a/common.mk b/common.mk index 70c9ceae1b..46ce286848 100644 --- a/common.mk +++ b/common.mk @@ -705,7 +705,7 @@ RUBY_H_INCLUDES = {$(VPATH)}ruby.h {$(VPATH)}config.h {$(VPATH)}defines.h \ acosh.$(OBJEXT): {$(VPATH)}acosh.c alloca.$(OBJEXT): {$(VPATH)}alloca.c {$(VPATH)}config.h -crypt.$(OBJEXT): {$(VPATH)}crypt.c {$(VPATH)}crypt.h +crypt_r.$(OBJEXT): {$(VPATH)}crypt_r.c {$(VPATH)}crypt.h dup2.$(OBJEXT): {$(VPATH)}dup2.c erf.$(OBJEXT): {$(VPATH)}erf.c explicit_bzero.$(OBJEXT): {$(VPATH)}explicit_bzero.c diff --git a/configure.in b/configure.in index edddb540e8..0906dadd68 100644 --- a/configure.in +++ b/configure.in @@ -1061,44 +1061,12 @@ AS_CASE(["$target_os"], test -d "$d" && RUBY_APPEND_OPTIONS(LDFLAGS, "-L$d") done ac_cv_type_getgroups=gid_t # getgroups() on Rosetta fills garbage - ac_cv_lib_crypt_crypt=no + ac_cv_lib_crypt_crypt_r=no ac_cv_func_fdatasync=no # Mac OS X wrongly reports it has fdatasync() ac_cv_func_vfork=no if test $gcc_major -lt 4 -o \( $gcc_major -eq 4 -a $gcc_minor -lt 3 \); then ac_cv_func___builtin_setjmp=no fi - AC_CACHE_CHECK(for broken crypt with 8bit chars, rb_cv_broken_crypt, - [AC_TRY_RUN([ -#include -#include -#include - -int -main() -{ - int i; - for (i = 0; i < 128*128; i++) { - char salt[2], buf[256], *s; - salt[0] = 0x80 | (i & 0x7f); - salt[1] = 0x80 | (i >> 7); - strcpy(buf, crypt("", salt)); - if (strcmp(buf, s = crypt("", salt))) { -#if 0 - printf("%.2x%.2x: %s -> %s\n", (unsigned char)salt[0], (unsigned char)salt[1], - buf+2, s+2); -#endif - return 1; - } - } - return 0; -} -], - 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 AC_CHECK_PROGS(codesign, codesign) if test -n "$codesign"; then POSTLINK="test -z '\$(RUBY_CODESIGN)' || $codesign -s '\$(RUBY_CODESIGN)' -f \$@" @@ -1195,7 +1163,7 @@ main() ac_cv_func_link=yes ac_cv_func_readlink=yes ac_cv_func_symlink=yes - ac_cv_lib_crypt_crypt=no + ac_cv_lib_crypt_crypt_r=no ac_cv_func_getpgrp_void=no ac_cv_func_memcmp_working=yes ac_cv_lib_dl_dlopen=no @@ -1250,7 +1218,7 @@ main() ], [ LIBS="-lm $LIBS"]) -AC_CHECK_LIB(crypt, crypt) # glibc (GNU/Linux, GNU/Hurd, GNU/kFreeBSD) +AC_CHECK_LIB(crypt, crypt_r) # glibc (GNU/Linux, GNU/Hurd, GNU/kFreeBSD) AC_CHECK_LIB(dl, dlopen) # Dynamic linking for SunOS/Solaris and SYSV AC_CHECK_LIB(dld, shl_load) # Dynamic linking for HP-UX AC_CHECK_LIB(socket, shutdown) # SunOS/Solaris @@ -2205,7 +2173,7 @@ AS_CASE(["$target_os"],[freebsd*],[ AC_REPLACE_FUNCS(acosh) AC_REPLACE_FUNCS(cbrt) -AC_REPLACE_FUNCS(crypt) +AC_REPLACE_FUNCS(crypt_r) AC_REPLACE_FUNCS(dup2) AC_REPLACE_FUNCS(erf) AC_REPLACE_FUNCS(explicit_bzero) diff --git a/missing/crypt.c b/missing/crypt_r.c similarity index 100% rename from missing/crypt.c rename to missing/crypt_r.c diff --git a/string.c b/string.c index 1fe74290c7..7c2b597711 100644 --- a/string.c +++ b/string.c @@ -29,6 +29,8 @@ #include #endif +#include + #define STRING_ENUMERATORS_WANTARRAY 0 /* next major */ #undef rb_str_new @@ -8373,13 +8375,10 @@ rb_str_oct(VALUE str) static VALUE rb_str_crypt(VALUE str, VALUE salt) { - extern char *crypt(const char *, const char *); + struct crypt_data data; VALUE result; const char *s, *saltp; char *res; -#ifdef BROKEN_CRYPT - char salt_8bit_clean[3]; -#endif StringValue(salt); mustnot_wchar(str); @@ -8392,15 +8391,8 @@ 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 - res = crypt(s, saltp); + data.initialized = 0; + res = crypt_r(s, saltp, &data); if (!res) { rb_sys_fail("crypt"); }