From dc98adf839d0d68c4c18647a1db2fb3dc9be8cc4 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 8 Nov 2001 06:43:14 +0000 Subject: * process.c (security): always give warning for insecure PATH. * dir.c (my_getcwd): do not rely on MAXPATHLEN. * file.c (rb_file_s_readlink): ditto. * file.c (path_check_1): ditto. * eval.c (rb_yield_0): should not call rb_f_block_given_p(). * string.c (rb_str_chomp_bang): should terminate string by NUL. * eval.c (rb_yield_0): better error message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1816 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- dir.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'dir.c') diff --git a/dir.c b/dir.c index 428f4aaaa6..a7673175e5 100644 --- a/dir.c +++ b/dir.c @@ -61,6 +61,8 @@ char *strchr _((char*,char)); #include +#include "util.h" + #ifndef HAVE_LSTAT #define lstat(path,st) stat(path,st) #endif @@ -430,21 +432,16 @@ static VALUE chdir_thread = Qnil; static VALUE chdir_restore(path) - const char *path; + char *path; { chdir_blocking--; if (chdir_blocking == 0) chdir_thread = Qnil; dir_chdir(path); + free(path); return Qnil; } -#ifdef HAVE_GETCWD -#define GETCWD(path) if (getcwd(path, sizeof(path)) == 0) rb_sys_fail(path) -#else -#define GETCWD(path) if (getwd(path) == 0) rb_sys_fail(path) -#endif - static VALUE dir_s_chdir(argc, argv, obj) int argc; @@ -473,9 +470,7 @@ dir_s_chdir(argc, argv, obj) } if (rb_block_given_p()) { - char cwd[MAXPATHLEN]; - - GETCWD(cwd); + char *cwd = my_getcwd(); chdir_blocking++; if (chdir_thread == Qnil) chdir_thread = rb_thread_current(); @@ -491,10 +486,11 @@ static VALUE dir_s_getwd(dir) VALUE dir; { - char path[MAXPATHLEN]; + char *path = my_getcwd(); + VALUE cwd = rb_tainted_str_new2(path); - GETCWD(path); - return rb_tainted_str_new2(path); + free(path); + return cwd; } static VALUE -- cgit v1.2.3