diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-06-22 21:43:02 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-06-22 21:43:02 +0000 |
commit | 6e708d72bb713ca9c7f8b25aa1f6ee8d8e83282a (patch) | |
tree | 326921323846a586522ca8e96068f0ae4eb4f595 /io.c | |
parent | bf8cec6db1cf9568a808449186f0bdb4e853ee36 (diff) | |
download | ruby-6e708d72bb713ca9c7f8b25aa1f6ee8d8e83282a.tar.gz |
* io.c (argf_next_argv): check for setting owner/group.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -6818,11 +6818,21 @@ argf_next_argv(VALUE argf) chmod(fn, st.st_mode); #endif if (st.st_uid!=st2.st_uid || st.st_gid!=st2.st_gid) { + int err; #ifdef HAVE_FCHOWN - (void)fchown(fw, st.st_uid, st.st_gid); + err = fchown(fw, st.st_uid, st.st_gid); #else - (void)chown(fn, st.st_uid, st.st_gid); + err = chown(fn, st.st_uid, st.st_gid); #endif + if (err && getuid() == 0 && st2.st_uid == 0) { + const char *wkfn = RSTRING_PTR(ARGF.filename); + rb_warn("Can't set owner/group of %s to same as %s: %s, skipping file", + wkfn, fn, strerror(errno)); + (void)close(fr); + (void)close(fw); + (void)unlink(wkfn); + goto retry; + } } #endif rb_stdout = prep_io(fw, FMODE_WRITABLE, rb_cFile, fn); |