erofs-utils: fix consistency + add NUL after root path
Igor Eisberg
igoreisberg at gmail.com
Sat Dec 18 13:35:37 AEDT 2021
>From 8b209620abfbd8147a2c771cb0126dcca528e34f Mon Sep 17 00:00:00 2001
From: Igor Ostapenko <igoreisberg at gmail.com>
Date: Sat, 18 Dec 2021 04:30:17 +0200
Subject: erofs-utils: fix consistency + add NUL after root path
Signed-off-by: Igor Ostapenko <igoreisberg at gmail.com>
---
fsck/main.c | 2 +-
lib/dir.c | 7 ++++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/fsck/main.c b/fsck/main.c
index df4845d..30d0a1b 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -400,7 +400,7 @@ static int erofsfsck_check_inode(erofs_nid_t pnid,
erofs_nid_t nid)
goto out;
/* XXXX: the dir depth should be restricted in order to avoid loops */
- if ((inode.i_mode & S_IFMT) == S_IFDIR) {
+ if (S_ISDIR(inode.i_mode)) {
struct erofs_dir_context ctx = {
.flags = EROFS_READDIR_VALID_PNID,
.pnid = pnid,
diff --git a/lib/dir.c b/lib/dir.c
index 340dce6..d5b8096 100644
--- a/lib/dir.c
+++ b/lib/dir.c
@@ -127,7 +127,7 @@ int erofs_iterate_dir(struct erofs_dir_context *ctx,
bool fsck)
erofs_off_t pos;
char buf[EROFS_BLKSIZ];
- if ((dir->i_mode & S_IFMT) != S_IFDIR)
+ if (!S_ISDIR(dir->i_mode))
return -ENOTDIR;
ctx->flags &= ~EROFS_READDIR_ALL_SPECIAL_FOUND;
@@ -244,13 +244,14 @@ int erofs_get_pathname(erofs_nid_t nid, char *buf,
size_t size)
};
if (nid == root.nid) {
- if (size == 0) {
- erofs_err("get_pathname buffer not large enough: len 1, size %zd",
+ if (size < 2) {
+ erofs_err("get_pathname buffer not large enough: len 2, size %zd",
size);
return -ENOMEM;
}
buf[0] = '/';
+ buf[1] = '\0';
return 0;
}
--
2.30.2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/linux-erofs/attachments/20211218/925faf37/attachment.htm>
More information about the Linux-erofs
mailing list