summaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/filecheck.c
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2021-06-29 04:34:01 +0200
committerLinus Torvalds <torvalds@linux-foundation.org>2021-06-29 19:53:46 +0200
commit54e948c60cc843b6e84dc44496edc91f51d2a28e (patch)
tree8646317910cb0caee63fd930ef3e02d6222dea88 /fs/ocfs2/filecheck.c
parentocfs2: remove unnecessary INIT_LIST_HEAD() (diff)
downloadlinux-54e948c60cc843b6e84dc44496edc91f51d2a28e.tar.xz
linux-54e948c60cc843b6e84dc44496edc91f51d2a28e.zip
ocfs2: fix snprintf() checking
The snprintf() function returns the number of bytes which would have been printed if the buffer was large enough. In other words it can return ">= remain" but this code assumes it returns "== remain". The run time impact of this bug is not very severe. The next iteration through the loop would trigger a WARN() when we pass a negative limit to snprintf(). We would then return success instead of -E2BIG. The kernel implementation of snprintf() will never return negatives so there is no need to check and I have deleted that dead code. Link: https://lkml.kernel.org/r/20210511135350.GV1955@kadam Fixes: a860f6eb4c6a ("ocfs2: sysfile interfaces for online file check") Fixes: 74ae4e104dfc ("ocfs2: Create stack glue sysfs files.") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Gang He <ghe@suse.com> Cc: Jun Piao <piaojun@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ocfs2/filecheck.c')
-rw-r--r--fs/ocfs2/filecheck.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/fs/ocfs2/filecheck.c b/fs/ocfs2/filecheck.c
index 90b8d300c1ee..de56e6231af8 100644
--- a/fs/ocfs2/filecheck.c
+++ b/fs/ocfs2/filecheck.c
@@ -326,11 +326,7 @@ static ssize_t ocfs2_filecheck_attr_show(struct kobject *kobj,
ret = snprintf(buf + total, remain, "%lu\t\t%u\t%s\n",
p->fe_ino, p->fe_done,
ocfs2_filecheck_error(p->fe_status));
- if (ret < 0) {
- total = ret;
- break;
- }
- if (ret == remain) {
+ if (ret >= remain) {
/* snprintf() didn't fit */
total = -E2BIG;
break;