summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-07-10 10:59:47 +0000
committerJim Meyering <jim@meyering.net>2003-07-10 10:59:47 +0000
commite2e3a9a41ccd404c2d1fe25e851d8f9bd5091414 (patch)
tree908d204b2dc6407dc0df95ccc2bec45b4972d840 /src
parent864de4b741d2e051f34d4c668035a6cc456a684d (diff)
downloadcoreutils-e2e3a9a41ccd404c2d1fe25e851d8f9bd5091414.tar.xz
(change_file_owner): Don't leak file descriptors when dereferencing symlinks.
Diffstat (limited to 'src')
-rw-r--r--src/chown-core.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/chown-core.c b/src/chown-core.c
index b38efaa89..a46dd7ef7 100644
--- a/src/chown-core.c
+++ b/src/chown-core.c
@@ -1,5 +1,5 @@
/* chown-core.c -- core functions for changing ownership.
- Copyright (C) 2000, 2002 Free Software Foundation.
+ Copyright (C) 2000, 2002, 2003 Free Software Foundation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -295,6 +295,8 @@ change_file_owner (int cmdline_arg, const char *file, uid_t uid, gid_t gid,
file and use fchown on the resulting descriptor. */
int fd = open (file, O_RDONLY | O_NONBLOCK | O_NOCTTY);
fail = (fd == -1 ? 1 : fchown (fd, new_uid, new_gid));
+ if (fd != -1)
+ close (fd);
}
else
{