ocfs2: use scnprintf() for avoiding potential buffer overflow
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: Takashi Iwai <tiwai@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Joseph Qi <jiangqi903@gmail.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Gang He <ghe@suse.com> Cc: Jun Piao <piaojun@huawei.com> Link: http://lkml.kernel.org/r/20200311093516.25300-1-tiwai@suse.de Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
0434c9f404
commit
d293d3af2d
@@ -1307,7 +1307,7 @@ static int o2hb_debug_open(struct inode *inode, struct file *file)
|
||||
|
||||
case O2HB_DB_TYPE_REGION_NUMBER:
|
||||
reg = (struct o2hb_region *)db->db_data;
|
||||
out += snprintf(buf + out, PAGE_SIZE - out, "%d\n",
|
||||
out += scnprintf(buf + out, PAGE_SIZE - out, "%d\n",
|
||||
reg->hr_region_num);
|
||||
goto done;
|
||||
|
||||
@@ -1317,12 +1317,12 @@ static int o2hb_debug_open(struct inode *inode, struct file *file)
|
||||
/* If 0, it has never been set before */
|
||||
if (lts)
|
||||
lts = jiffies_to_msecs(jiffies - lts);
|
||||
out += snprintf(buf + out, PAGE_SIZE - out, "%lu\n", lts);
|
||||
out += scnprintf(buf + out, PAGE_SIZE - out, "%lu\n", lts);
|
||||
goto done;
|
||||
|
||||
case O2HB_DB_TYPE_REGION_PINNED:
|
||||
reg = (struct o2hb_region *)db->db_data;
|
||||
out += snprintf(buf + out, PAGE_SIZE - out, "%u\n",
|
||||
out += scnprintf(buf + out, PAGE_SIZE - out, "%u\n",
|
||||
!!reg->hr_item_pinned);
|
||||
goto done;
|
||||
|
||||
@@ -1331,8 +1331,8 @@ static int o2hb_debug_open(struct inode *inode, struct file *file)
|
||||
}
|
||||
|
||||
while ((i = find_next_bit(map, db->db_len, i + 1)) < db->db_len)
|
||||
out += snprintf(buf + out, PAGE_SIZE - out, "%d ", i);
|
||||
out += snprintf(buf + out, PAGE_SIZE - out, "\n");
|
||||
out += scnprintf(buf + out, PAGE_SIZE - out, "%d ", i);
|
||||
out += scnprintf(buf + out, PAGE_SIZE - out, "\n");
|
||||
|
||||
done:
|
||||
i_size_write(inode, out);
|
||||
|
@@ -443,8 +443,8 @@ static int o2net_fill_bitmap(char *buf, int len)
|
||||
o2net_fill_node_map(map, sizeof(map));
|
||||
|
||||
while ((i = find_next_bit(map, O2NM_MAX_NODES, i + 1)) < O2NM_MAX_NODES)
|
||||
out += snprintf(buf + out, PAGE_SIZE - out, "%d ", i);
|
||||
out += snprintf(buf + out, PAGE_SIZE - out, "\n");
|
||||
out += scnprintf(buf + out, PAGE_SIZE - out, "%d ", i);
|
||||
out += scnprintf(buf + out, PAGE_SIZE - out, "\n");
|
||||
|
||||
return out;
|
||||
}
|
||||
|
Reference in New Issue
Block a user