mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
fix: get_cmdpath returns NULL if executable is absent in first directory searched
This commit is contained in:
parent
a5a93be3d0
commit
bd01c79838
1 changed files with 7 additions and 6 deletions
|
|
@ -3,10 +3,10 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* simple_filename_exp.c :+: :+: :+: */
|
/* simple_filename_exp.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/02 13:40:10 by jguelen #+# #+# */
|
/* 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
|
** 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
|
** denied error. oldpath is to store the first occurrence of a regular file
|
||||||
** corresponding to the filepath but not executable.
|
** 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,
|
static char *select_path(char *filepath, char **oldpath, char **path,
|
||||||
struct stat *fstat)
|
struct stat *fstat)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ft_errno(FT_ESUCCESS);
|
|
||||||
ret = stat(filepath, fstat);
|
ret = stat(filepath, fstat);
|
||||||
if (ret == -1)
|
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, F_OK) == 0 && ret == 0 && S_ISREG(fstat->st_mode))
|
||||||
{
|
{
|
||||||
if (access(filepath, X_OK) != 0)
|
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);
|
tmp = select_path(filepath, &oldpath, path, fstat);
|
||||||
if (tmp)
|
if (tmp)
|
||||||
return (filepath);
|
return (filepath);
|
||||||
else if (!tmp && ft_errno_get() == FT_STATFAIL)
|
free(filepath);
|
||||||
return (free(filepath), NULL);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
path_split_destroy(path);
|
path_split_destroy(path);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue