diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | common.mk | 2 | ||||
-rw-r--r-- | configure.in | 54 | ||||
-rw-r--r-- | missing/crypt.c (renamed from missing/crypt_r.c) | 0 | ||||
-rw-r--r-- | string.c | 21 | ||||
-rw-r--r-- | win32/Makefile.sub | 2 |
6 files changed, 82 insertions, 6 deletions
@@ -1,3 +1,12 @@ +Wed Jun 1 15:58:20 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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. + Wed Jun 1 14:07:53 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> * missing/crypt_r.c (a64toi): initialize statically and fix out of @@ -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_r.$(OBJEXT): {$(VPATH)}crypt_r.c {$(VPATH)}crypt.h +crypt.$(OBJEXT): {$(VPATH)}crypt.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 0906dadd68..81d4488005 100644 --- a/configure.in +++ b/configure.in @@ -1061,12 +1061,57 @@ 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_r=no + ac_cv_lib_crypt_crypt=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 <stdio.h> +#include <unistd.h> +#include <string.h> + +void +broken_crypt(const char *salt, const char *buf1, const char *buf2) +{ +#if 0 + printf("%.2x%.2x: %s -> %s\n", (unsigned char)salt[0], (unsigned char)salt[1], + buf1+2, buf2+2); +#endif +} + +int +main() +{ + int i; + char salt[2], buf[256], *s; + for (i = 0; i < 128*128; i++) { + salt[0] = 0x80 | (i & 0x7f); + salt[1] = 0x80 | (i >> 7); + strcpy(buf, crypt("", salt)); + if (strcmp(buf, s = crypt("", salt))) { + broken_crypt(salt, buf, s); + return 1; + } + } + salt[0] = salt[1] = ' '; + strcpy(buf, crypt("", salt)); + salt[0] = salt[1] = 0x80 | ' '; + if (strcmp(buf, s = crypt("", salt))) { + broken_crypt(salt, buf, s); + 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 \$@" @@ -1163,7 +1208,7 @@ AS_CASE(["$target_os"], ac_cv_func_link=yes ac_cv_func_readlink=yes ac_cv_func_symlink=yes - ac_cv_lib_crypt_crypt_r=no + ac_cv_lib_crypt_crypt=no ac_cv_func_getpgrp_void=no ac_cv_func_memcmp_working=yes ac_cv_lib_dl_dlopen=no @@ -1218,7 +1263,7 @@ AS_CASE(["$target_os"], ], [ LIBS="-lm $LIBS"]) -AC_CHECK_LIB(crypt, crypt_r) # glibc (GNU/Linux, GNU/Hurd, GNU/kFreeBSD) +AC_CHECK_LIB(crypt, crypt) # 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 @@ -2173,7 +2218,7 @@ AS_CASE(["$target_os"],[freebsd*],[ AC_REPLACE_FUNCS(acosh) AC_REPLACE_FUNCS(cbrt) -AC_REPLACE_FUNCS(crypt_r) +AC_REPLACE_FUNCS(crypt) AC_REPLACE_FUNCS(dup2) AC_REPLACE_FUNCS(erf) AC_REPLACE_FUNCS(explicit_bzero) @@ -2253,6 +2298,7 @@ AC_CHECK_FUNCS(chroot) AC_CHECK_FUNCS(chsize) AC_CHECK_FUNCS(clock_gettime) AC_CHECK_FUNCS(cosh) +AC_CHECK_FUNCS(crypt_r) AC_CHECK_FUNCS(daemon) AC_CHECK_FUNCS(dirfd) AC_CHECK_FUNCS(dl_iterate_phdr) diff --git a/missing/crypt_r.c b/missing/crypt.c index d55937865f..d55937865f 100644 --- a/missing/crypt_r.c +++ b/missing/crypt.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"); } diff --git a/win32/Makefile.sub b/win32/Makefile.sub index ed9b499a5f..d2f89eea5f 100644 --- a/win32/Makefile.sub +++ b/win32/Makefile.sub @@ -247,7 +247,7 @@ LIBS = $(LIBS) iphlpapi.lib LIBS = $(LIBS) imagehlp.lib shlwapi.lib $(EXTLIBS) !endif !if !defined(MISSING) -MISSING = crypt_r.obj ffs.obj langinfo.obj lgamma_r.obj strlcat.obj strlcpy.obj win32/win32.obj win32/file.obj setproctitle.obj +MISSING = crypt.obj ffs.obj langinfo.obj lgamma_r.obj strlcat.obj strlcpy.obj win32/win32.obj win32/file.obj setproctitle.obj !if $(RT_VER) < 120 MISSING = $(MISSING) acosh.obj cbrt.obj erf.obj tgamma.obj !endif |