Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

load.c : add String's subclass to prevent double expansion of load path.

  • Loading branch information...
commit 98bbe30badeb85a3c704d6dfdef7d66a82ee86cd 1 parent a8a212a
@funny-falcon authored
Showing with 20 additions and 0 deletions.
  1. +14 −0 file.c
  2. +1 −0  internal.h
  3. +5 −0 load.c
View
14 file.c
@@ -167,6 +167,10 @@ rb_get_path_check(VALUE obj, int level)
}
StringValue(tmp);
+ if (RBASIC(obj)->klass == rb_cExpandedPath) {
+ return obj;
+ }
+
tmp = file_path_convert(tmp);
if (obj != tmp && insecure_obj_p(tmp, level)) {
rb_insecure_operation();
@@ -2904,6 +2908,16 @@ file_expand_path(VALUE fname, VALUE dname, int abs_mode, VALUE result)
BUFINIT();
tainted = OBJ_TAINTED(fname);
+ if (RBASIC(fname)->klass == rb_cExpandedPath) {
+ size_t dlen = RSTRING_LEN(fname);
+ BUFCHECK(dlen > buflen);
+ strncpy(buf, RSTRING_PTR(fname), dlen + 1);
+ rb_str_set_len(result, dlen);
+ rb_enc_associate(result, rb_enc_check(result, fname));
+ ENC_CODERANGE_CLEAR(result);
+ return result;
+ }
+
if (s[0] == '~' && abs_mode == 0) { /* execute only if NOT absolute_path() */
long userlen = 0;
tainted = 1;
View
1  internal.h
@@ -120,6 +120,7 @@ VALUE rb_get_load_path(void);
NORETURN(void rb_load_fail(VALUE, const char*));
void rb_reset_expanded_cache();
void rb_load_path_ary_push(VALUE path);
+extern VALUE rb_cExpandedPath;
/* math.c */
VALUE rb_math_atan2(VALUE, VALUE);
View
5 load.c
@@ -32,6 +32,7 @@ static VALUE rb_checked_expanded_cache(int*);
static void rb_set_expanded_cache(VALUE, int);
static VALUE rb_expand_load_paths(long, VALUE*, int*);
static int cached_expanded_load_path = 1;
+VALUE rb_cExpandedPath;
VALUE
rb_get_expanded_load_path(void)
@@ -900,6 +901,7 @@ rb_expand_load_paths(long pathc, VALUE* paths, int *has_relative)
p = RSTRING_PTR(path);
*has_relative = *has_relative || !rb_is_absolute_path(p);
path = rb_file_expand_path(path, Qnil);
+ RBASIC(path)->klass = rb_cExpandedPath;
rb_str_freeze(path);
rb_ary_push(expanded, path);
}
@@ -992,6 +994,9 @@ rb_load_path_init(void)
cached_expanded_load_path = atoi(cached_flag);
}
+ rb_cExpandedPath = rb_class_new(rb_cString); /* XXX could GC collect it before next line is executed? */
+ rb_iv_set(rb_cFile, "expanded_path", rb_cExpandedPath); /* prevent from GC */
+
/* Do all the magick if user did not disable it
* with RUBY_CACHED_LOAD_PATH=0 environment variable
*/
Please sign in to comment.
Something went wrong with that request. Please try again.