Skip to content

Commit

Permalink
Raise security exception if loading from tainted load path.
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviershay committed May 15, 2011
1 parent 460fb8f commit 88f9bab
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions load.c
Expand Up @@ -837,7 +837,7 @@ rb_find_file_relative(VALUE fname)
// TODO: Consistent naming across expanded_file_name and expanded_path

VALUE
rb_find_file_in_load_path(VALUE fname)
rb_find_file_in_load_path(VALUE fname, int safe)
{
long i, j;
VALUE load_path = rb_get_expanded_load_path();
Expand All @@ -853,6 +853,9 @@ rb_find_file_in_load_path(VALUE fname)
expanded_path = rb_funcall(expanded_path, rb_intern("+"), 1, rb_str_new2(available_extensions[j]));

if (rb_feature_exists(expanded_path)) {
if (safe >= 1 && OBJ_TAINTED(expanded_path)) {
rb_raise(rb_eSecurityError, "Loading from unsafe file %s", RSTRING_PTR(expanded_path));
}
return expanded_path;
}
}
Expand Down Expand Up @@ -933,7 +936,7 @@ rb_require_safe_2(VALUE fname, int safe)
} else if (rb_is_absolute_path(RSTRING_PTR(fname))) {
path = rb_find_file_absolute(fname);
} else {
path = rb_find_file_in_load_path(fname);
path = rb_find_file_in_load_path(fname, safe);
}
// TODO: WTF does the second part here do
// TODO: Raise LoadError if file does not exist
Expand Down

1 comment on commit 88f9bab

@xaviershay
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passes all ruby and rubyspec require tests.

      user     system      total        real
500 requires  0.030000   0.020000   0.050000 (  0.051625)
1000 requires  0.070000   0.040000   0.110000 (  0.098384)
1500 requires  0.100000   0.050000   0.150000 (  0.154987)
2000 requires  0.140000   0.070000   0.210000 (  0.208448)
2500 requires  0.180000   0.100000   0.280000 (  0.276569)

Please sign in to comment.