From bd01c798381979b18ad9aa7fbcc9f878f2e3dcb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Thu, 27 Mar 2025 16:10:41 +0100 Subject: [PATCH] fix: get_cmdpath returns NULL if executable is absent in first directory searched --- src/subst/simple_filename_exp.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/subst/simple_filename_exp.c b/src/subst/simple_filename_exp.c index 74785d1..3e1451b 100644 --- a/src/subst/simple_filename_exp.c +++ b/src/subst/simple_filename_exp.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* simple_filename_exp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/02 13:40:10 by jguelen #+# #+# */ -/* Updated: 2025/03/21 17:33:50 by jguelen ### ########.fr */ +/* Updated: 2025/03/27 18:39:23 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,16 +55,18 @@ static char **get_paths_array(t_env *env) ** is the value stored in oldpath that will be used resulting in a Permission ** denied error. oldpath is to store the first occurrence of a regular file ** corresponding to the filepath but not executable. +** +** We disregard all stat(2) failures, since bash does the same and treats them +** all to mean that the file does not exist. */ static char *select_path(char *filepath, char **oldpath, char **path, struct stat *fstat) { int ret; - ft_errno(FT_ESUCCESS); ret = stat(filepath, fstat); if (ret == -1) - return (path_split_destroy(path), ft_errno(FT_STATFAIL), NULL); + return (NULL); if (access(filepath, F_OK) == 0 && ret == 0 && S_ISREG(fstat->st_mode)) { if (access(filepath, X_OK) != 0) @@ -114,8 +116,7 @@ static char *deal_with_filled_path(char *filename, char **path, tmp = select_path(filepath, &oldpath, path, fstat); if (tmp) return (filepath); - else if (!tmp && ft_errno_get() == FT_STATFAIL) - return (free(filepath), NULL); + free(filepath); i++; } path_split_destroy(path);