commit: bcef2914067aa920ea327bd06b006f62bd0c4f21
parent a88f648b172aebe300717ac307caf62a021e5100
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Mon, 16 Dec 2024 23:20:52 +0100
cmd/{ln,mv}: check fstatat return value before errno
Diffstat:
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/cmd/ln.c b/cmd/ln.c
@@ -179,7 +179,14 @@ main(int argc, char *argv[])
errno = 0;
struct stat dest_status;
int ret_stat = fstatat(AT_FDCWD, argv[1], &dest_status, AT_SYMLINK_NOFOLLOW);
- if(argc == 2 && (errno == ENOENT || (ret_stat == 0 && !S_ISDIR(dest_status.st_mode))))
+ if(
+ // clang-format off
+ argc == 2 && (
+ (ret_stat != 0 && errno == ENOENT) ||
+ (ret_stat == 0 && !S_ISDIR(dest_status.st_mode))
+ )
+ // clang-format on
+ )
{
errno = 0;
int ret = do_link(argv[0], argv[1]);
diff --git a/cmd/mv.c b/cmd/mv.c
@@ -466,7 +466,14 @@ main(int argc, char *argv[])
struct stat dest_status;
int ret_stat = fstatat(destdir.fd, argv[1], &dest_status, 0);
- if(argc == 2 && (errno == ENOENT || (ret_stat == 0 && !S_ISDIR(dest_status.st_mode))))
+ if(
+ // clang-format off
+ argc == 2 && (
+ (ret_stat != 0 && errno == ENOENT) ||
+ (ret_stat == 0 && !S_ISDIR(dest_status.st_mode))
+ )
+ // clang-format on
+ )
{
int ret = do_renameat(srcdir, argv[0], destdir, argv[1]);