[v2 PATCH] expand: Check d_type in expmeta before recursing

Herbert Xu <[email protected]>
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
On Tue, Jun 04, 2024 at 11:28:35PM +0200, Jilles Tjoelker wrote:
>
> Good idea, but DT_UNKNOWN might also be a directory or a symlink to one.

Thanks for catching this!

---8<---
If the directory pointer is not a directory, a symlink or an unknown
entity, do not recurse into expmeta.

Signed-off-by: Herbert Xu <[email protected]>
---
 src/expand.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/expand.c b/src/expand.c
index 345c498..6912e39 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -1722,6 +1722,9 @@ static char *expmeta(char *name, unsigned name_len, size_t expdir_len)
 
 		if (*dname == '.' && !matchdot)
 			goto check_int;
+		if (c && dp->d_type != DT_DIR && dp->d_type != DT_LNK &&
+		    dp->d_type != DT_UNKNOWN)
+			goto check_int;
 		len = strlen(dname) + 1;
 		p = dname;
 		if (!FNMATCH_IS_ENABLED) {
-- 
2.39.2

-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.