aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2023-03-23 02:52:09 +0000
committerEric Biggers <ebiggers@google.com>2023-03-23 02:59:22 +0000
commit08c122f12fc231029a74c24b969e337203c7b6e2 (patch)
treedf397540fdfc686ab85cab7fe598f6baafa7e6f5
parent60634ff32a0d8c0d7942c6e522a74a5051d4b6e9 (diff)
downloade2fsprogs-08c122f12fc231029a74c24b969e337203c7b6e2.tar.gz
ext2simg: fix same_file() with symlinks
Fix same_file() to use stat() instead of lstat() when checking the paths, so that symlinks are dereferenced. This is needed to be consistent with how the paths are actually accessed later. Otherwise, not all cases where the input and output file are the same are detected. Also just use the stat() result to check whether the output file exists, instead of using a separate call to access(). Fixes: db6f320912cf ("AOSP: android: add the ext2simg tool") Change-Id: Ie36981f9dbc19494732f518488a75fb92c0f0343 Signed-off-by: Eric Biggers <ebiggers@google.com>
-rw-r--r--contrib/android/ext2simg.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/contrib/android/ext2simg.c b/contrib/android/ext2simg.c
index d1b5dc4e..2bf76b91 100644
--- a/contrib/android/ext2simg.c
+++ b/contrib/android/ext2simg.c
@@ -188,13 +188,13 @@ static bool same_file(const char *in, const char *out)
{
struct stat st1, st2;
- if (access(out, F_OK) == -1)
- return false;
-
- if (lstat(in, &st1) == -1)
+ if (stat(in, &st1) == -1)
ext2fs_fatal(errno, "stat %s\n", in);
- if (lstat(out, &st2) == -1)
+ if (stat(out, &st2) == -1) {
+ if (errno == ENOENT)
+ return false;
ext2fs_fatal(errno, "stat %s\n", out);
+ }
return st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino;
}