Messages in this thread Patch in this message | | | From | Yang Shen <> | Subject | [PATCH 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf' | Date | Sat, 25 Jul 2020 11:44:37 +0800 |
| |
Replace 'sprintf' with 'scnprintf' to avoid overrun.
Signed-off-by: Yang Shen <shenyang39@huawei.com> Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com> --- drivers/crypto/hisilicon/zip/zip_main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c index df1a16f..1883d1b 100644 --- a/drivers/crypto/hisilicon/zip/zip_main.c +++ b/drivers/crypto/hisilicon/zip/zip_main.c @@ -428,7 +428,7 @@ static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf, return -EINVAL; } spin_unlock_irq(&file->lock); - ret = sprintf(tbuf, "%u\n", val); + ret = scnprintf(tbuf, HZIP_BUF_SIZE, "%u\n", val); return simple_read_from_buffer(buf, count, pos, tbuf, ret); }
@@ -514,13 +514,16 @@ static int hisi_zip_core_debug_init(struct hisi_qm *qm) struct debugfs_regset32 *regset; struct dentry *tmp_d; char buf[HZIP_BUF_SIZE]; - int i; + int i, ret;
for (i = 0; i < HZIP_CORE_NUM; i++) { if (i < HZIP_COMP_CORE_NUM) - sprintf(buf, "comp_core%d", i); + ret = scnprintf(buf, HZIP_BUF_SIZE, "comp_core%d", i); else - sprintf(buf, "decomp_core%d", i - HZIP_COMP_CORE_NUM); + ret = scnprintf(buf, HZIP_BUF_SIZE, "decomp_core%d", + i - HZIP_COMP_CORE_NUM); + if (!ret) + return -ENOMEM;
regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); if (!regset) -- 2.7.4
| |