Re: [hackers] [sbase] [PATCH 1/2] [libutil/recurse] only opendir if recursing

From: Michael Forney <mforney_AT_mforney.org>
Date: Sun, 1 Oct 2017 00:35:23 -0700

On 2017-09-30, David Phillips <david_AT_sighup.nz> wrote:
> Previous behaviour was to call opendir regardless of if we are actually
> going to be recursing into the direectory. Additionally, some utilities
> require like chmod that DIRFIRST causes the fn to execute before the
> opendir is called.

Hi David,

Thanks for the patch. The general idea seems good to me.

> ---
> libutil/recurse.c | 15 +++++++--------
> 1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/libutil/recurse.c b/libutil/recurse.c
> index e2b8a6e..b356d2c 100644
> --- a/libutil/recurse.c
> +++ b/libutil/recurse.c
> _AT_@ -54,18 +54,17 @@ recurse(const char *path, void *data, struct recursor
> *r)
> if (h->ino == st.st_ino && h->dev == st.st_dev)
> return;
>
> - if (!(dp = opendir(path))) {
> - if (!(r->flags & SILENT)) {
> - weprintf("opendir %s:", path);
> - recurse_status = 1;
> - }
> - return;
> - }
> -
> if (!r->depth && (r->flags & DIRFIRST))
> (r->fn)(path, &st, data, r);
>
> if (!r->maxdepth || r->depth + 1 < r->maxdepth) {
> + if (!r->maxdepth && !(dp = opendir(path))) {

I don't understand the `!r->maxdepth` check here. If `r->depth + 1 <
r->maxdepth` is used to enter the outer branch, won't an uninitialized
`dp` to be passed to readdir?

> + if (!(r->flags & SILENT)) {
> + weprintf("opendir %s:", path);
> + recurse_status = 1;
> + }
> + return;
> + }
> while ((d = readdir(dp))) {
> if (r->follow == 'H') {
> statf_name = "lstat";
> --
> 2.14.1
Received on Sun Oct 01 2017 - 09:35:23 CEST

This archive was generated by hypermail 2.3.0 : Sun Oct 01 2017 - 09:36:22 CEST