1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* eval.c (rb_provided): extension should be guessed using

rb_find_file_noext().

* eval.c (rb_f_require): should call rb_feature_p() after
  extension completion.

* eval.c (rb_eval): add CHECK_INTS before next, redo, retry to
  avoid potential uninterruptable infinite loop.

* file.c (rb_file_s_expand_path): use CharNext() to expand.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2001-07-27 09:12:12 +00:00
parent 980f816479
commit 0abedcd807
3 changed files with 69 additions and 15 deletions

View file

@ -1,12 +1,40 @@
Fri Jul 27 18:07:27 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_provided): extension should be guessed using
rb_find_file_noext().
* eval.c (rb_f_require): should call rb_feature_p() after
extension completion.
Fri Jul 27 16:25:52 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_eval): add CHECK_INTS before next, redo, retry to
avoid potential uninterruptable infinite loop.
Thu Jul 26 11:27:12 2001 WATANABE Hirofumi <eban@ruby-lang.org> Thu Jul 26 11:27:12 2001 WATANABE Hirofumi <eban@ruby-lang.org>
* file.c (rb_find_file_noext, rb_find_file): fix tilde expansion * file.c (rb_find_file_noext, rb_find_file): fix tilde expansion
problem. problem.
Wed Jul 25 17:54:20 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* file.c (rb_file_s_expand_path): use CharNext() to expand.
Wed Jul 25 17:16:26 2001 Akinori MUSHA <knu@iDaemons.org> Wed Jul 25 17:16:26 2001 Akinori MUSHA <knu@iDaemons.org>
* intern.h: add some missing function prototypes. * intern.h: add some missing function prototypes.
Wed Jul 25 15:50:05 2001 Guy Decoux <decoux@moulon.inra.fr>
* file.c (rb_file_s_expand_path): should not expand "." and ".."
not following dirsep.
Wed Jul 25 12:15:32 2001 WATANABE Hirofumi <eban@ruby-lang.org>
* file.c (rb_find_file_noext): should update f by expanded path.
* file.c (rb_find_file): ditto.
Tue Jul 24 23:10:47 2001 Nobuyoshi.Nakada <nobu.nakada@nifty.ne.jp> Tue Jul 24 23:10:47 2001 Nobuyoshi.Nakada <nobu.nakada@nifty.ne.jp>
* file.c (strrdirsep): multi-byte pathname and DOSish separater * file.c (strrdirsep): multi-byte pathname and DOSish separater

18
eval.c
View file

@ -2398,6 +2398,7 @@ rb_eval(self, n)
break; break;
case NODE_NEXT: case NODE_NEXT:
CHECK_INTS;
if (node->nd_stts) { if (node->nd_stts) {
return_value(avalue_to_svalue(rb_eval(self, node->nd_stts))); return_value(avalue_to_svalue(rb_eval(self, node->nd_stts)));
} }
@ -2408,10 +2409,12 @@ rb_eval(self, n)
break; break;
case NODE_REDO: case NODE_REDO:
CHECK_INTS;
JUMP_TAG(TAG_REDO); JUMP_TAG(TAG_REDO);
break; break;
case NODE_RETRY: case NODE_RETRY:
CHECK_INTS;
JUMP_TAG(TAG_RETRY); JUMP_TAG(TAG_RETRY);
break; break;
@ -5385,7 +5388,14 @@ int
rb_provided(feature) rb_provided(feature)
const char *feature; const char *feature;
{ {
return rb_feature_p(feature, Qfalse); VALUE f = rb_str_new2(feature);
if (strrchr(feature, '.') == 0) {
if (rb_find_file_noext(&f) == 0) {
return Qfalse;
}
}
return rb_feature_p(RSTRING(f)->ptr, Qfalse);
} }
static void static void
@ -5413,8 +5423,6 @@ rb_f_require(obj, fname)
volatile int safe = ruby_safe_level; volatile int safe = ruby_safe_level;
SafeStringValue(fname); SafeStringValue(fname);
if (rb_feature_p(RSTRING(fname)->ptr, Qtrue))
return Qfalse;
ext = strrchr(RSTRING(fname)->ptr, '.'); ext = strrchr(RSTRING(fname)->ptr, '.');
if (ext) { if (ext) {
if (strcmp(".rb", ext) == 0) { if (strcmp(".rb", ext) == 0) {
@ -5480,6 +5488,8 @@ rb_f_require(obj, fname)
rb_raise(rb_eLoadError, "No such file to load -- %s", RSTRING(fname)->ptr); rb_raise(rb_eLoadError, "No such file to load -- %s", RSTRING(fname)->ptr);
load_dyna: load_dyna:
if (rb_feature_p(RSTRING(feature)->ptr, Qfalse))
return Qfalse;
rb_provide_feature(feature); rb_provide_feature(feature);
{ {
int volatile old_vmode = scope_vmode; int volatile old_vmode = scope_vmode;
@ -5500,6 +5510,8 @@ rb_f_require(obj, fname)
return Qtrue; return Qtrue;
load_rb: load_rb:
if (rb_feature_p(RSTRING(feature)->ptr, Qtrue))
return Qfalse;
ruby_safe_level = 0; ruby_safe_level = 0;
rb_provide_feature(feature); rb_provide_feature(feature);
/* loading ruby library should be serialized. */ /* loading ruby library should be serialized. */

38
file.c
View file

@ -1332,7 +1332,7 @@ rb_file_s_expand_path(argc, argv)
VALUE *argv; VALUE *argv;
{ {
VALUE fname, dname; VALUE fname, dname;
char *s, *p; char *s, *p, *sbeg, *b;
char buf[MAXPATHLEN+2]; char buf[MAXPATHLEN+2];
char *bend = buf + sizeof(buf) - 2; char *bend = buf + sizeof(buf) - 2;
int tainted; int tainted;
@ -1340,7 +1340,7 @@ rb_file_s_expand_path(argc, argv)
rb_scan_args(argc, argv, "11", &fname, &dname); rb_scan_args(argc, argv, "11", &fname, &dname);
tainted = OBJ_TAINTED(fname); tainted = OBJ_TAINTED(fname);
s = StringValuePtr(fname); s = sbeg = StringValuePtr(fname);
p = buf; p = buf;
if (s[0] == '~') { if (s[0] == '~') {
if (isdirsep(s[1]) || s[1] == '\0') { if (isdirsep(s[1]) || s[1] == '\0') {
@ -1360,10 +1360,13 @@ rb_file_s_expand_path(argc, argv)
struct passwd *pwPtr; struct passwd *pwPtr;
s++; s++;
#endif #endif
b = s;
while (*s && !isdirsep(*s)) { while (*s && !isdirsep(*s)) {
*p++ = *s++; s = CharNext(s);
if (p >= bend) goto toolong;
} }
if (p + (s-b) >= bend) goto toolong;
memcpy(p, b, s-b);
p += s-b;
*p = '\0'; *p = '\0';
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
pwPtr = getpwnam(buf); pwPtr = getpwnam(buf);
@ -1381,10 +1384,13 @@ rb_file_s_expand_path(argc, argv)
#if defined DOSISH #if defined DOSISH
/* skip drive letter */ /* skip drive letter */
else if (ISALPHA(s[0]) && s[1] == ':' && isdirsep(s[2])) { else if (ISALPHA(s[0]) && s[1] == ':' && isdirsep(s[2])) {
b = s;
while (*s && !isdirsep(*s)) { while (*s && !isdirsep(*s)) {
*p++ = *s++; s = CharNext(s);
if (p >= bend) goto toolong;
} }
if (p + (s-b) >= bend) goto toolong;
memcpy(p, b, s-b);
p += s-b;
} }
#endif #endif
else if (!isdirsep(*s)) { else if (!isdirsep(*s)) {
@ -1411,10 +1417,10 @@ rb_file_s_expand_path(argc, argv)
} }
*p = '/'; *p = '/';
for ( ; *s; s++) { while (*s) {
switch (*s) { switch (*s) {
case '.': case '.':
if (*(s+1)) { if (*(s+1) && (s == sbeg || isdirsep(*(s - 1)))) {
switch (*++s) { switch (*++s) {
case '.': case '.':
if (*(s+1) == '\0' || isdirsep(*(s+1))) { if (*(s+1) == '\0' || isdirsep(*(s+1))) {
@ -1441,6 +1447,9 @@ rb_file_s_expand_path(argc, argv)
*++p = '.'; *++p = *s; break; *++p = '.'; *++p = *s; break;
} }
} }
else {
*++p = '.';
}
break; break;
case '/': case '/':
#if defined DOSISH #if defined DOSISH
@ -1448,9 +1457,14 @@ rb_file_s_expand_path(argc, argv)
#endif #endif
if (!isdirsep(*p)) *++p = '/'; break; if (!isdirsep(*p)) *++p = '/'; break;
default: default:
*++p = *s; b = s;
if (p >= bend) goto toolong; s = CharNext(s);
p = CharNext(p);
if (p + (s-b) >= bend) goto toolong;
memcpy(p, b, s-b);
continue;
} }
s = CharNext(s);
} }
/* Place a \0 at end. If path ends with a "/", delete it */ /* Place a \0 at end. If path ends with a "/", delete it */
@ -2278,7 +2292,7 @@ rb_find_file_noext(filep)
if (rb_safe_level() >= 2 && OBJ_TAINTED(fname)) { if (rb_safe_level() >= 2 && OBJ_TAINTED(fname)) {
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
} }
f = STR2CSTR(fname); f = StringValuePtr(fname);
*filep = fname; *filep = fname;
} }
@ -2329,7 +2343,7 @@ rb_find_file(path)
if (rb_safe_level() >= 2 && OBJ_TAINTED(path)) { if (rb_safe_level() >= 2 && OBJ_TAINTED(path)) {
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
} }
f = STR2CSTR(path); f = StringValuePtr(path);
} }
#if defined(__MACOS__) || defined(riscos) #if defined(__MACOS__) || defined(riscos)