diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-10-04 05:04:22 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-10-04 05:04:22 +0000 |
commit | 43c4522fbdbe37d2fd70d05dc263ff4fed703cbe (patch) | |
tree | 1cbc481588e6f5c1b9cffd84547503b7c240e56d /io.c | |
parent | f9b895e41a52b9a2a7208dbd72d58272800250f0 (diff) | |
download | ruby-43c4522fbdbe37d2fd70d05dc263ff4fed703cbe.tar.gz ruby-43c4522fbdbe37d2fd70d05dc263ff4fed703cbe.tar.xz ruby-43c4522fbdbe37d2fd70d05dc263ff4fed703cbe.zip |
* io.c (rb_file_open_internal, rb_io_reopen): fname might be altered
while GC. [ruby-dev:24408]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@6995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -2285,6 +2285,8 @@ rb_io_mode_modenum(mode) return flags; } +#define MODENUM_MAX 4 + static char* rb_io_modenum_mode(flags, mode) int flags; @@ -2413,12 +2415,13 @@ rb_file_open_internal(io, fname, mode) const char *fname, *mode; { OpenFile *fptr; + char mbuf[MODENUM_MAX]; MakeOpenFile(io, fptr); fptr->mode = rb_io_mode_flags(mode); - fptr->f = rb_fopen(fname, mode); fptr->path = strdup(fname); + fptr->f = rb_fopen(fptr->path, rb_io_flags_mode(fptr->mode, mbuf)); return io; } @@ -2439,7 +2442,7 @@ rb_file_sysopen_internal(io, fname, flags, mode) OpenFile *fptr; int fd; char *m; - char mbuf[4]; + char mbuf[MODENUM_MAX]; MakeOpenFile(io, fptr); @@ -2714,7 +2717,7 @@ rb_io_popen(str, argc, argv, klass) { char *mode; VALUE pname, pmode, port; - char mbuf[4]; + char mbuf[MODENUM_MAX]; if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) { mode = "r"; @@ -3144,7 +3147,7 @@ rb_io_reopen(argc, argv, file) VALUE file; { VALUE fname, nmode; - char *mode; + char mode[MODENUM_MAX]; OpenFile *fptr; rb_secure(4); @@ -3165,10 +3168,10 @@ rb_io_reopen(argc, argv, file) } if (!NIL_P(nmode)) { - mode = StringValuePtr(nmode); + strncpy(mode, StringValuePtr(nmode), sizeof(mode)); + mode[sizeof(mode) - 1] = 0; } else { - mode = ALLOCA_N(char, 4); rb_io_flags_mode(fptr->mode, mode); } @@ -3180,7 +3183,7 @@ rb_io_reopen(argc, argv, file) fptr->path = strdup(RSTRING(fname)->ptr); fptr->mode = rb_io_mode_flags(mode); if (!fptr->f) { - fptr->f = rb_fopen(RSTRING(fname)->ptr, mode); + fptr->f = rb_fopen(fptr->path, mode); if (fptr->f2) { fclose(fptr->f2); fptr->f2 = 0; @@ -3736,7 +3739,7 @@ rb_io_initialize(argc, argv, io) VALUE fnum, mode; OpenFile *fp; int fd, flags; - char mbuf[4]; + char mbuf[MODENUM_MAX]; rb_secure(4); rb_scan_args(argc, argv, "11", &fnum, &mode); |