提交 cb2fab4e 编写于 作者: T Takashi Iwai 提交者: Yang Yingliang

xfs: Use scnprintf() for avoiding potential buffer overflow

mainline inclusion
from mainline-v5.7-rc1
commit 17bb60b7
category: bugfix
bugzilla: 33322
CVE: NA

---------------------------

Since snprintf() returns the would-be-output size instead of the
actual output size, the succeeding calls may go beyond the given
buffer limit.  Fix it by replacing with scnprintf().
Signed-off-by: NTakashi Iwai <tiwai@suse.de>
Reviewed-by: NDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: NDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Nyu kuai <yukuai3@huawei.com>
Reviewed-by: Nzhangyi (F) <yi.zhang@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 830a5fbb
...@@ -58,13 +58,13 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf) ...@@ -58,13 +58,13 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
/* Loop over all stats groups */ /* Loop over all stats groups */
for (i = j = 0; i < ARRAY_SIZE(xstats); i++) { for (i = j = 0; i < ARRAY_SIZE(xstats); i++) {
len += snprintf(buf + len, PATH_MAX - len, "%s", len += scnprintf(buf + len, PATH_MAX - len, "%s",
xstats[i].desc); xstats[i].desc);
/* inner loop does each group */ /* inner loop does each group */
for (; j < xstats[i].endpoint; j++) for (; j < xstats[i].endpoint; j++)
len += snprintf(buf + len, PATH_MAX - len, " %u", len += scnprintf(buf + len, PATH_MAX - len, " %u",
counter_val(stats, j)); counter_val(stats, j));
len += snprintf(buf + len, PATH_MAX - len, "\n"); len += scnprintf(buf + len, PATH_MAX - len, "\n");
} }
/* extra precision counters */ /* extra precision counters */
for_each_possible_cpu(i) { for_each_possible_cpu(i) {
...@@ -73,9 +73,9 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf) ...@@ -73,9 +73,9 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
xs_read_bytes += per_cpu_ptr(stats, i)->s.xs_read_bytes; xs_read_bytes += per_cpu_ptr(stats, i)->s.xs_read_bytes;
} }
len += snprintf(buf + len, PATH_MAX-len, "xpc %Lu %Lu %Lu\n", len += scnprintf(buf + len, PATH_MAX-len, "xpc %Lu %Lu %Lu\n",
xs_xstrat_bytes, xs_write_bytes, xs_read_bytes); xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
len += snprintf(buf + len, PATH_MAX-len, "debug %u\n", len += scnprintf(buf + len, PATH_MAX-len, "debug %u\n",
#if defined(DEBUG) #if defined(DEBUG)
1); 1);
#else #else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册