From c45908e41f47c88674b73a754ecd0535449b667a Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 27 Aug 2002 08:31:08 +0000 Subject: * file.c (rb_find_file): $LOAD_PATH must not be empty. * file.c (rb_find_file_ext): ditto. * range.c (range_eq): class check should be based on range.class, instead of Range to work with Range.dup. * range.c (range_eql): ditto. * class.c (rb_mod_dup): need to preserve metaclass and flags. * object.c (rb_cstr_to_dbl): had a buffer overrun. * marshal.c (w_class): integrate singleton check into a funciton to follow DRY principle. * marshal.c (w_uclass): should check singleton method. * object.c (rb_obj_dup): dmark and dfree functions must be match for T_DATA type. * object.c (rb_obj_dup): class of the duped object must be match to the class of the original. * re.c (rb_reg_quote): do not escape \t, \f, \r, \n, for they are not regular expression metacharacters. * time.c (time_s_alloc): use time_free instead of free (null check, also serves for type mark). * time.c (time_s_at): check dfree function too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index 781cd9ac82..00b2fb070c 100644 --- a/file.c +++ b/file.c @@ -2015,22 +2015,22 @@ rb_stat_init(obj, fname) } static VALUE -rb_stat_clone(obj) - VALUE obj; +rb_stat_become(obj, orig) + VALUE obj, orig; { struct stat *nst; - VALUE clone; - - clone = rb_obj_alloc(RBASIC(obj)->klass); - CLONESETUP(clone,obj); - if (DATA_PTR(obj)) { + /* need better argument type check */ + if (!rb_obj_is_kind_of(orig, rb_obj_class(obj))) { + rb_raise(rb_eTypeError, "wrong argument type"); + } + if (DATA_PTR(orig)) { nst = ALLOC(struct stat); - *nst = *(struct stat*)DATA_PTR(obj); - DATA_PTR(clone) = nst; + *nst = *(struct stat*)DATA_PTR(orig); + DATA_PTR(obj) = nst; } - return clone; + return obj; } static VALUE @@ -2457,6 +2457,7 @@ rb_find_file_ext(filep, ext) VALUE str = RARRAY(rb_load_path)->ptr[i]; SafeStringValue(str); + if (RSTRING(str)->len == 0) return 0; path = RSTRING(str)->ptr; for (j=0; ext[j]; j++) { fname = rb_str_dup(*filep); @@ -2520,15 +2521,23 @@ rb_find_file(path) } } tmp = rb_ary_join(tmp, rb_str_new2(PATH_SEP)); - lpath = StringValuePtr(tmp); - if (rb_safe_level() >= 2 && !rb_path_check(lpath)) { - rb_raise(rb_eSecurityError, "loading from unsafe path %s", lpath); + if (RSTRING(tmp)->len == 0) { + lpath = 0; + } + else { + lpath = RSTRING(tmp)->ptr; + if (rb_safe_level() >= 2 && !rb_path_check(lpath)) { + rb_raise(rb_eSecurityError, "loading from unsafe path %s", lpath); + } } } else { lpath = 0; } + if (!lpath) { + return 0; /* no path, no load */ + } f = dln_find_file(f, lpath); if (file_load_ok(f)) { return rb_str_new2(f); @@ -2646,7 +2655,7 @@ Init_File() rb_cStat = rb_define_class_under(rb_cFile, "Stat", rb_cObject); rb_define_singleton_method(rb_cStat, "allocate", rb_stat_s_alloc, 0); rb_define_method(rb_cStat, "initialize", rb_stat_init, 1); - rb_define_method(rb_cStat, "clone", rb_stat_clone, 0); + rb_define_method(rb_cStat, "become", rb_stat_become, 1); rb_include_module(rb_cStat, rb_mComparable); -- cgit v1.2.3