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

* dir.c (dir_s_chdir): raise if environment variable HOME/LOGDIR

not set.

* dir.c (glob_helper): avoid infinite loop on a file name with
  wildcard characters. (ruby-bugs#PR177)


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2001-09-06 08:42:57 +00:00
parent 26d37a1b6e
commit 2e5674c2ab
2 changed files with 23 additions and 11 deletions

View file

@ -1,3 +1,11 @@
Thu Sep 6 17:38:18 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* dir.c (dir_s_chdir): raise if environment variable HOME/LOGDIR
not set.
* dir.c (glob_helper): avoid infinite loop on a file name with
wildcard characters. (ruby-bugs#PR177)
Thu Sep 6 03:15:24 2001 Yukihiro Matsumoto <matz@ruby-lang.org> Thu Sep 6 03:15:24 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* class.c (rb_include_module): should check whole ancestors to * class.c (rb_include_module): should check whole ancestors to

26
dir.c
View file

@ -409,6 +409,7 @@ dir_s_chdir(argc, argv, obj)
dist = getenv("HOME"); dist = getenv("HOME");
if (!dist) { if (!dist) {
dist = getenv("LOGDIR"); dist = getenv("LOGDIR");
if (!dist) rb_raise(rb_eArgError, "HOME/LOGDIR not set");
} }
} }
@ -569,8 +570,9 @@ extract_elem(path)
#endif #endif
void void
rb_glob_helper(path, flags, func, arg) rb_glob_helper(path, sub, flags, func, arg)
char *path; char *path;
char *sub;
int flags; int flags;
void (*func) _((const char*, VALUE)); void (*func) _((const char*, VALUE));
VALUE arg; VALUE arg;
@ -578,14 +580,14 @@ rb_glob_helper(path, flags, func, arg)
struct stat st; struct stat st;
char *p, *m; char *p, *m;
if (!has_magic(path, 0, flags)) { p = sub ? sub : path;
if (!has_magic(p, 0, flags)) {
if (rb_sys_stat(path, &st) == 0) { if (rb_sys_stat(path, &st) == 0) {
(*func)(path, arg); (*func)(path, arg);
} }
return; return;
} }
p = path;
while (p) { while (p) {
if (*p == '/') p++; if (*p == '/') p++;
m = strchr(p, '/'); m = strchr(p, '/');
@ -611,10 +613,11 @@ rb_glob_helper(path, flags, func, arg)
} }
if (S_ISDIR(st.st_mode)) { if (S_ISDIR(st.st_mode)) {
if (m && strcmp(magic, "**") == 0) { if (m && strcmp(magic, "**") == 0) {
int n = strlen(base);
recursive = 1; recursive = 1;
buf = ALLOC_N(char, strlen(base)+strlen(m)+3); buf = ALLOC_N(char, n+strlen(m)+3);
sprintf(buf, "%s%s%s", base, (*base)?"":".", m); sprintf(buf, "%s%s%s", base, (*base)?"":".", m);
rb_glob_helper(buf, flags, func, arg); rb_glob_helper(buf, buf+n, flags, func, arg);
free(buf); free(buf);
} }
dirp = opendir(dir); dirp = opendir(dir);
@ -644,9 +647,10 @@ rb_glob_helper(path, flags, func, arg)
continue; continue;
} }
if (S_ISDIR(st.st_mode)) { if (S_ISDIR(st.st_mode)) {
strcat(buf, "/**"); char *t = buf+strlen(buf);
strcat(buf, m); strcpy(t, "/**");
rb_glob_helper(buf, flags, func, arg); strcpy(t+3, m);
rb_glob_helper(buf, t, flags, func, arg);
} }
free(buf); free(buf);
continue; continue;
@ -676,7 +680,7 @@ rb_glob_helper(path, flags, func, arg)
char *t = ALLOC_N(char, len+mlen+1); char *t = ALLOC_N(char, len+mlen+1);
sprintf(t, "%s%s", link->path, m); sprintf(t, "%s%s", link->path, m);
rb_glob_helper(t, flags, func, arg); rb_glob_helper(t, t+len, flags, func, arg);
free(t); free(t);
} }
tmp = link; tmp = link;
@ -695,7 +699,7 @@ rb_glob(path, func, arg)
void (*func)(); void (*func)();
VALUE arg; VALUE arg;
{ {
rb_glob_helper(path, FNM_PERIOD, func, arg); rb_glob_helper(path, 0, FNM_PERIOD, func, arg);
} }
void void
@ -704,7 +708,7 @@ rb_iglob(path, func, arg)
void (*func) _((const char*, VALUE)); void (*func) _((const char*, VALUE));
VALUE arg; VALUE arg;
{ {
rb_glob_helper(path, FNM_PERIOD|FNM_NOCASE, func, arg); rb_glob_helper(path, 0, FNM_PERIOD|FNM_NOCASE, func, arg);
} }
static void static void