From 54723137491054781667e56533e2e0eb5186964b Mon Sep 17 00:00:00 2001 From: James Youngman Date: Fri, 9 Apr 2010 22:20:10 +0100 Subject: [PATCH] Pass filename, rather than NULL, to open in pred_samefile. To: address@hidden * find/parser.c (parse_samefile): Since collect_arg_stat_info increments *arg_ptr, argv[*arg_ptr] is often NULL. Use filename instead, as that's the variable in which we store the name of our file. The purpose of the fd was only to attempt to keep the inode number stable on systems that don't really have inode numbers, so this change should have no functional effect on POSIX systems. * find/parser.c (parse_samefile): Use open_cloexec to open the reference file, so that we don't leak a file descriptor. Signed-off-by: James Youngman --- ChangeLog | 14 ++++++++++++++ find/parser.c | 11 ++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index af42fb0..6fe36f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2010-04-09 James Youngman + + * find/parser.c (parse_samefile): Use open_cloexec to open the + reference file, so that we don't leak a file descriptor. + +2010-04-09 Roberto Reale (tiny change) + + * find/parser.c (parse_samefile): Since collect_arg_stat_info + increments *arg_ptr, argv[*arg_ptr] is often NULL. Use filename + instead, as that's the variable in which we store the name of our + file. The purpose of the fd was only to attempt to keep the inode + number stable on systems that don't really have inode numbers, so + this change should have no functional effect on POSIX systems. + 2010-04-08 James Youngman Move on from 4.5.8. diff --git a/find/parser.c b/find/parser.c index f29f58b..fb6c753 100644 --- a/find/parser.c +++ b/find/parser.c @@ -43,6 +43,7 @@ #include "error.h" #include "findutils-version.h" #include "safe-atoi.h" +#include "fdleak.h" #include @@ -2412,9 +2413,9 @@ parse_samefile (const struct parser_table* entry, char **argv, int *arg_ptr) { /* Race condition here. The file might become a * symbolic link in between our call to stat and - * the call to open. + * the call to open_cloexec. */ - fd = open (argv[*arg_ptr], openflags); + fd = open_cloexec (filename, openflags); if (fd >= 0) { @@ -2423,7 +2424,7 @@ parse_samefile (const struct parser_table* entry, char **argv, int *arg_ptr) */ if (0 != fstat (fd, &fst)) { - fatal_target_file_error (errno, argv[*arg_ptr]); + fatal_target_file_error (errno, filename); } else { @@ -2432,8 +2433,8 @@ parse_samefile (const struct parser_table* entry, char **argv, int *arg_ptr) * open, fst may contain the stat information for the * destination of the link, not the link itself. */ - if ((*options.xstat) (argv[*arg_ptr], &st)) - fatal_target_file_error (errno, argv[*arg_ptr]); + if ((*options.xstat) (filename, &st)) + fatal_target_file_error (errno, filename); if ((options.symlink_handling == SYMLINK_NEVER_DEREF) && (!options.open_nofollow_available)) -- 1.7.0