Skip to content

Commit

Permalink
* eval.c (rb_provided): return true only for features loaded from
Browse files Browse the repository at this point in the history
  .rb files, and not search actual library type.  [ruby-dev:30414]

* eval.c (rb_feature_p): check loading_tbl if the given ext is
  empty.  [ruby-dev:30452]

* eval.c (rb_feature_p): fix possible buffer overrun.


git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_6@11966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
knu committed Mar 3, 2007
1 parent 08c210f commit 261fbd9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
@@ -1,3 +1,13 @@
Sat Mar 3 18:36:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>

* eval.c (rb_provided): return true only for features loaded from
.rb files, and not search actual library type. [ruby-dev:30414]

* eval.c (rb_feature_p): check loading_tbl if the given ext is
empty. [ruby-dev:30452]

* eval.c (rb_feature_p): fix possible buffer overrun.

Sat Mar 3 16:30:39 2007 Akinori MUSHA <knu@iDaemons.org>

* env.h (SCOPE_CLONE): Introduce a new scope flag to prevent a
Expand Down
30 changes: 18 additions & 12 deletions eval.c
Expand Up @@ -6937,6 +6937,9 @@ static const char *const loadable_ext[] = {
0
};

static int rb_feature_p _((const char *, const char *, int));
static int search_required _((VALUE, VALUE *, VALUE *));

static int
rb_feature_p(feature, ext, rb)
const char *feature, *ext;
Expand Down Expand Up @@ -6973,15 +6976,15 @@ rb_feature_p(feature, ext, rb)
}
if (loading_tbl) {
if (st_lookup(loading_tbl, (st_data_t)feature, 0)) {
if (ext) return 'u';
if (!ext) return 'u';
return strcmp(ext, ".rb") ? 's' : 'r';
}
else {
char *buf;

if (ext) return 0;
if (ext && *ext) return 0;
buf = ALLOCA_N(char, len + DLEXT_MAXLEN + 1);
strcpy(buf, feature);
MEMCPY(buf, feature, char, len);
for (i = 0; (e = loadable_ext[i]) != 0; i++) {
strncpy(buf + len, e, DLEXT_MAXLEN + 1);
if (st_lookup(loading_tbl, (st_data_t)buf, 0)) {
Expand All @@ -6993,21 +6996,24 @@ rb_feature_p(feature, ext, rb)
return 0;
}

static int search_required(VALUE, VALUE *, VALUE *);

int
rb_provided(feature)
const char *feature;
{
VALUE fname, path;
const char *ext = strrchr(feature, '.');

if (rb_feature_p(feature, 0, Qfalse))
return Qtrue;
if (search_required(rb_str_new2(feature), &fname, &path) != 0) {
feature = RSTRING_PTR(fname);
if (rb_feature_p(feature, strrchr(feature, '.'), Qfalse))
return Qtrue;
if (ext && !strchr(ext, '/')) {
if (strcmp(".rb", ext) == 0) {
if (rb_feature_p(feature, ext, Qtrue)) return Qtrue;
return Qfalse;
}
else if (IS_SOEXT(ext) || IS_DLEXT(ext)) {
return Qfalse; /* may be overriden by .rb file */
}
}
if (rb_feature_p(feature, feature + strlen(feature), Qtrue))
return Qtrue;

return Qfalse;
}

Expand Down

0 comments on commit 261fbd9

Please sign in to comment.