summaryrefslogtreecommitdiff
path: root/load.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-04 14:47:15 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-04 14:47:15 +0000
commit90490d673211f523f27ffc5c79d15deb05d31967 (patch)
treee1629abe31922bda9e71943f04ebd2f64fd49e29 /load.c
parent205b5c9cd64a5a0d5f104159e919e82a03b10cb4 (diff)
merge revision(s) 39637,40900: [Backport #8440]
load.c: reorder conditions * load.c (loaded_feature_path): reorder conditions so simple comparision comes first. * load.c (loaded_feature_path): fix invalid read by index underflow. the beginning of name is also a boundary as well as just after '/'. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@41065 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'load.c')
-rw-r--r--load.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/load.c b/load.c
index 498e7e9990..d123798a47 100644
--- a/load.c
+++ b/load.c
@@ -315,7 +315,7 @@ loaded_feature_path(const char *name, long vlen, const char *feature, long len,
if (vlen < len+1) return 0;
if (!strncmp(name+(vlen-len), feature, len)) {
- plen = vlen - len - 1;
+ plen = vlen - len;
}
else {
for (e = name + vlen; name != e && *e != '.' && *e != '/'; --e);
@@ -323,16 +323,20 @@ loaded_feature_path(const char *name, long vlen, const char *feature, long len,
e-name < len ||
strncmp(e-len, feature, len))
return 0;
- plen = e - name - len - 1;
+ plen = e - name - len;
}
- if (type == 's' && !IS_DLEXT(&name[plen+len+1])
- || type == 'r' && !IS_RBEXT(&name[plen+len+1])
- || name[plen] != '/') {
- return 0;
+ if (plen > 0 && name[plen-1] != '/') {
+ return 0;
+ }
+ if (type == 's' ? !IS_DLEXT(&name[plen+len]) :
+ type == 'r' ? !IS_RBEXT(&name[plen+len]) :
+ 0) {
+ return 0;
}
/* Now name == "#{prefix}/#{feature}#{ext}" where ext is acceptable
(possibly empty) and prefix is some string of length plen. */
+ if (plen > 0) --plen; /* exclude '.' */
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
VALUE p = RARRAY_PTR(load_path)[i];
const char *s = StringValuePtr(p);