Project

General

Profile

Feature #15797 » use-native-realpath.patch

jeremyevans0 (Jeremy Evans), 04/26/2019 08:59 PM

View differences:

configure.ac
AC_CHECK_FUNCS(qsort_r)
AC_CHECK_FUNCS(qsort_s)
AC_CHECK_FUNCS(readlink)
AC_CHECK_FUNCS(realpath)
AC_CHECK_FUNCS(round)
AC_CHECK_FUNCS(sched_getaffinity)
AC_CHECK_FUNCS(seekdir)
file.c
return 0;
}
static VALUE rb_file_join(VALUE ary);
static VALUE
rb_check_realpath_internal(VALUE basedir, VALUE path, enum rb_realpath_mode mode)
{
#ifdef HAVE_REALPATH
rb_encoding *origenc;
char resolved_buf[PATH_MAX];
VALUE unresolved_path;
VALUE resolved;
unresolved_path = rb_str_dup_frozen(path);
origenc = rb_enc_get(unresolved_path);
if (*RSTRING_PTR(unresolved_path) != '/' && !NIL_P(basedir)) {
unresolved_path = rb_file_join(rb_ary_new_from_args(2, basedir, unresolved_path));
}
unresolved_path = TO_OSPATH(unresolved_path);
if(realpath(RSTRING_PTR(unresolved_path), resolved_buf) == NULL) {
if (mode == RB_REALPATH_CHECK) {
return Qnil;
}
rb_sys_fail_path(unresolved_path);
}
resolved = rb_enc_str_new_cstr(resolved_buf, origenc);
if (mode == RB_REALPATH_STRICT || mode == RB_REALPATH_CHECK) {
struct stat st;
if (rb_stat(resolved, &st) < 0) {
if (mode == RB_REALPATH_STRICT) {
rb_sys_fail_path(unresolved_path);
}
return Qnil;
}
}
if(rb_enc_str_coderange(resolved) == ENC_CODERANGE_BROKEN) {
rb_enc_associate(resolved, rb_ascii8bit_encoding());
}
#else
long prefixlen;
VALUE resolved;
VALUE unresolved_path;
......
if (realpath_rec(&prefixlen, &resolved, path_names, Qnil, loopcheck, mode, 1))
return Qnil;
RB_GC_GUARD(curdir);
if (origenc != rb_enc_get(resolved)) {
if (rb_enc_str_asciionly_p(resolved)) {
rb_enc_associate(resolved, origenc);
......
resolved = rb_str_conv_enc(resolved, NULL, origenc);
}
}
#endif
OBJ_INFECT(resolved, unresolved_path);
/* Always taint, as a path component not in path or basedir could
be returned due to it being the referent of a symlink.
*/
rb_obj_taint(resolved);
RB_GC_GUARD(unresolved_path);
RB_GC_GUARD(curdir);
return resolved;
}
......
return rb_assoc_new(rb_file_dirname(path), rb_file_s_basename(1,&path));
}
static VALUE rb_file_join(VALUE ary);
static VALUE
file_inspect_join(VALUE ary, VALUE arg, int recur)
{
test/ruby/test_file.rb
assert_predicate(File.realpath(base, dir), :tainted?)
base.untaint
dir.untaint
assert_not_predicate(File.realpath(base, dir), :tainted?)
assert_predicate(File.realpath(base, dir), :tainted?)
assert_predicate(Dir.chdir(dir) {File.realpath(base)}, :tainted?)
}
end
(1-1/4)