mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (rb_file_open_internal, rb_io_reopen): fname might be altered
while GC. [ruby-dev:24408] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
28604a2544
commit
16d052477b
2 changed files with 16 additions and 8 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Oct 4 14:04:14 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (rb_file_open_internal, rb_io_reopen): fname might be altered
|
||||||
|
while GC. [ruby-dev:24408]
|
||||||
|
|
||||||
Mon Oct 4 12:53:45 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
Mon Oct 4 12:53:45 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||||
|
|
||||||
* ext/tk/lib/tk/optiondb.rb: support definition of command
|
* ext/tk/lib/tk/optiondb.rb: support definition of command
|
||||||
|
|
19
io.c
19
io.c
|
@ -2285,6 +2285,8 @@ rb_io_mode_modenum(mode)
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MODENUM_MAX 4
|
||||||
|
|
||||||
static char*
|
static char*
|
||||||
rb_io_modenum_mode(flags, mode)
|
rb_io_modenum_mode(flags, mode)
|
||||||
int flags;
|
int flags;
|
||||||
|
@ -2413,12 +2415,13 @@ rb_file_open_internal(io, fname, mode)
|
||||||
const char *fname, *mode;
|
const char *fname, *mode;
|
||||||
{
|
{
|
||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
|
char mbuf[MODENUM_MAX];
|
||||||
|
|
||||||
MakeOpenFile(io, fptr);
|
MakeOpenFile(io, fptr);
|
||||||
|
|
||||||
fptr->mode = rb_io_mode_flags(mode);
|
fptr->mode = rb_io_mode_flags(mode);
|
||||||
fptr->f = rb_fopen(fname, mode);
|
|
||||||
fptr->path = strdup(fname);
|
fptr->path = strdup(fname);
|
||||||
|
fptr->f = rb_fopen(fptr->path, rb_io_flags_mode(fptr->mode, mbuf));
|
||||||
|
|
||||||
return io;
|
return io;
|
||||||
}
|
}
|
||||||
|
@ -2439,7 +2442,7 @@ rb_file_sysopen_internal(io, fname, flags, mode)
|
||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
int fd;
|
int fd;
|
||||||
char *m;
|
char *m;
|
||||||
char mbuf[4];
|
char mbuf[MODENUM_MAX];
|
||||||
|
|
||||||
MakeOpenFile(io, fptr);
|
MakeOpenFile(io, fptr);
|
||||||
|
|
||||||
|
@ -2714,7 +2717,7 @@ rb_io_popen(str, argc, argv, klass)
|
||||||
{
|
{
|
||||||
char *mode;
|
char *mode;
|
||||||
VALUE pname, pmode, port;
|
VALUE pname, pmode, port;
|
||||||
char mbuf[4];
|
char mbuf[MODENUM_MAX];
|
||||||
|
|
||||||
if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) {
|
if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) {
|
||||||
mode = "r";
|
mode = "r";
|
||||||
|
@ -3144,7 +3147,7 @@ rb_io_reopen(argc, argv, file)
|
||||||
VALUE file;
|
VALUE file;
|
||||||
{
|
{
|
||||||
VALUE fname, nmode;
|
VALUE fname, nmode;
|
||||||
char *mode;
|
char mode[MODENUM_MAX];
|
||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
|
@ -3165,10 +3168,10 @@ rb_io_reopen(argc, argv, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NIL_P(nmode)) {
|
if (!NIL_P(nmode)) {
|
||||||
mode = StringValuePtr(nmode);
|
strncpy(mode, StringValuePtr(nmode), sizeof(mode));
|
||||||
|
mode[sizeof(mode) - 1] = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mode = ALLOCA_N(char, 4);
|
|
||||||
rb_io_flags_mode(fptr->mode, mode);
|
rb_io_flags_mode(fptr->mode, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3180,7 +3183,7 @@ rb_io_reopen(argc, argv, file)
|
||||||
fptr->path = strdup(RSTRING(fname)->ptr);
|
fptr->path = strdup(RSTRING(fname)->ptr);
|
||||||
fptr->mode = rb_io_mode_flags(mode);
|
fptr->mode = rb_io_mode_flags(mode);
|
||||||
if (!fptr->f) {
|
if (!fptr->f) {
|
||||||
fptr->f = rb_fopen(RSTRING(fname)->ptr, mode);
|
fptr->f = rb_fopen(fptr->path, mode);
|
||||||
if (fptr->f2) {
|
if (fptr->f2) {
|
||||||
fclose(fptr->f2);
|
fclose(fptr->f2);
|
||||||
fptr->f2 = 0;
|
fptr->f2 = 0;
|
||||||
|
@ -3736,7 +3739,7 @@ rb_io_initialize(argc, argv, io)
|
||||||
VALUE fnum, mode;
|
VALUE fnum, mode;
|
||||||
OpenFile *fp;
|
OpenFile *fp;
|
||||||
int fd, flags;
|
int fd, flags;
|
||||||
char mbuf[4];
|
char mbuf[MODENUM_MAX];
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
rb_scan_args(argc, argv, "11", &fnum, &mode);
|
rb_scan_args(argc, argv, "11", &fnum, &mode);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue