[PATCH v2] erofs-utils: check the return value of lseek in inode.c
Yue Hu
zbestahu at gmail.com
Tue Dec 13 20:23:17 AEDT 2022
From: Yue Hu <huyue2 at coolpad.com>
Need to check if we got an error. Also, make erofs_write_file() static.
Signed-off-by: Yue Hu <huyue2 at coolpad.com>
---
v2: check ret < 0 rather than ret == -1
lib/inode.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/lib/inode.c b/lib/inode.c
index 9de4dec..e675b45 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -406,7 +406,7 @@ static int write_uncompressed_file_from_fd(struct erofs_inode *inode, int fd)
return 0;
}
-int erofs_write_file(struct erofs_inode *inode)
+static int erofs_write_file(struct erofs_inode *inode)
{
int ret, fd;
@@ -1196,7 +1196,10 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(int fd, const char *name)
struct erofs_inode *inode;
int ret;
- lseek(fd, 0, SEEK_SET);
+ ret = lseek(fd, 0, SEEK_SET);
+ if (ret < 0)
+ return ERR_PTR(-errno);
+
ret = fstat64(fd, &st);
if (ret)
return ERR_PTR(-errno);
@@ -1223,7 +1226,10 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(int fd, const char *name)
ret = erofs_write_compressed_file(inode, fd);
if (ret == -ENOSPC) {
- lseek(fd, 0, SEEK_SET);
+ ret = lseek(fd, 0, SEEK_SET);
+ if (ret < 0)
+ return ERR_PTR(-errno);
+
ret = write_uncompressed_file_from_fd(inode, fd);
}
--
2.17.1
More information about the Linux-erofs
mailing list