From 7f5cf7a100555ddf4deee2a6dfe776ffb3ed6334 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 6 Oct 2004 15:10:43 +0000 Subject: [PATCH] * io.c (rb_io_s_sysopen): preserve path in the buffer allocated by ALLOCA_N() to prevent modification. [ruby-dev:24438] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ io.c | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 885c344703..da9a8c0814 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Oct 7 00:08:37 2004 Yukihiro Matsumoto + + * io.c (rb_io_s_sysopen): preserve path in the buffer allocated by + ALLOCA_N() to prevent modification. [ruby-dev:24438] + Wed Oct 6 09:21:00 2004 Yukihiro Matsumoto * io.c (rb_io_mode_flags): preserve append mode flag. diff --git a/io.c b/io.c index 7670a6995f..de80872ca4 100644 --- a/io.c +++ b/io.c @@ -2572,11 +2572,11 @@ rb_file_sysopen_internal(io, fname, flags, mode) MakeOpenFile(io, fptr); - fd = rb_sysopen(fname, flags, mode); + fptr->path = strdup(fname); m = rb_io_modenum_mode(flags); fptr->mode = rb_io_modenum_flags(flags); + fd = rb_sysopen(fptr->path, flags, mode); fptr->f = rb_fdopen(fd, m); - fptr->path = strdup(fname); return io; } @@ -3007,12 +3007,11 @@ rb_open_file(argc, argv, io) VALUE io; { VALUE fname, vmode, perm; - char *path, *mode; + char *mode; int flags, fmode; rb_scan_args(argc, argv, "12", &fname, &vmode, &perm); FilePathValue(fname); - path = RSTRING(fname)->ptr; if (FIXNUM_P(vmode) || !NIL_P(perm)) { if (FIXNUM_P(vmode)) { @@ -3024,7 +3023,7 @@ rb_open_file(argc, argv, io) } fmode = NIL_P(perm) ? 0666 : NUM2INT(perm); - rb_file_sysopen_internal(io, path, flags, fmode); + rb_file_sysopen_internal(io, RSTRING(fname)->ptr, flags, fmode); } else { mode = NIL_P(vmode) ? "r" : StringValuePtr(vmode); @@ -3079,6 +3078,7 @@ rb_io_s_sysopen(argc, argv) { VALUE fname, vmode, perm; int flags, fmode, fd; + char *path; rb_scan_args(argc, argv, "12", &fname, &vmode, &perm); FilePathValue(fname); @@ -3092,7 +3092,9 @@ rb_io_s_sysopen(argc, argv) if (NIL_P(perm)) fmode = 0666; else fmode = NUM2INT(perm); - fd = rb_sysopen(RSTRING(fname)->ptr, flags, fmode); + path = ALLOCA_N(char, strlen(RSTRING(fname)->ptr)+1); + strcpy(path, RSTRING(fname)->ptr); + fd = rb_sysopen(path, flags, fmode); return INT2NUM(fd); }