* 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
This commit is contained in:
nobu 2016-06-01 00:48:08 +00:00
Родитель 6cc652a23d
Коммит 3c31685e11
5 изменённых файлов: 14 добавлений и 50 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Wed Jun 1 09:48:06 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_crypt): use reentrant crypt_r.
Wed Jun 1 09:37:26 2016 NAKAMURA Usaku <usa@ruby-lang.org>
* missing/crypt.c (des_setkey): void function never returns any value.

Просмотреть файл

@ -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

Просмотреть файл

@ -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 <stdio.h>
#include <unistd.h>
#include <string.h>
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)

Просмотреть файл

Просмотреть файл

@ -29,6 +29,8 @@
#include <unistd.h>
#endif
#include <crypt.h>
#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");
}