Re: [LTP] [PATCH v4] tst_tmpdir: Fix buffer overflow in tst_tmpdir.c

Cyril Hrubis
2026-02-26T08:59:55Z

Hi!
> diff --git a/lib/tst_tmpdir.c b/lib/tst_tmpdir.c
> index 9b024a74e..0c06a306c 100644
> --- a/lib/tst_tmpdir.c
> +++ b/lib/tst_tmpdir.c
> @@ -186,8 +186,10 @@ static int purge_dirat(int dir_fd, const char *path, char **errptr)
> continue;
>
> /* Recursively remove the current entry */
> - if (rmobjat(subdir_fd, dir_ent->d_name, errptr) != 0)
> + if (rmobjat(subdir_fd, dir_ent->d_name, errptr) != 0) {
> + close(subdir_fd); <<<<<<<<<< first close
> ret_val = -1;
> + }
> }
>
> closedir(dir); <<<<<<<<<<<<< second close

Ah, right, we hand the fd to the fdopendir() and it's closed in the
closedir() call. I've missed that since the closedir() is not shown in
the diff since that part of the code wasn't modified and haven't shown
up in the diff.

The patch looks good to me then.

--
Cyril Hrubis
chrubis@suse.cz