Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1868232pxa; Sun, 23 Aug 2020 20:19:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCrVUIlUcICN8pnx1QMTfuibYDGu30plCG01dbzFTDdwWSuThtsfq1AC/YOGnGFGCwvtLe X-Received: by 2002:aa7:ca0c:: with SMTP id y12mr3490253eds.251.1598239159274; Sun, 23 Aug 2020 20:19:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598239159; cv=none; d=google.com; s=arc-20160816; b=MoTcskA52bkAjEXAosbcJnnGuAQ3m4dPcNhXhcFcQHjn2rb+K+N5H5J0us9khr3IKw 1c2OOHKg6GHX21rhNdfBb4DT3Ht9xNnXTsQsEGc3vVWGzsIaYxMLl8QJj0oBgJmENfN3 tBc6na2dcknMJ/I1MT01nLcDQDJNBU05jXntb0UFKQO8UoWJtH6aQFPwPciDJK5u3+OX eLxvc2dm5b1wTLQlih+j7MsZ+zBbVBjn8djW+uN1GK4uAW+VHcyWS6gxwou5akr2cRN4 vNXcmCFlJ8YyKy+jNRksi0B0J+tBzVTAtNVS8iwbyuuP5PIoJz/YqJNO0tuODFN3J2vr GvVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=yy2aqetwijV5IkVoTSrUrv/D6x64CUVdNbcOV7Ro1rk=; b=cR2+Adv7vBkqmF2ygVlyjtjwvnhU/rzLkqQcnqJrqbwSSwPz96yeEWXxB/lNmHlJNr om5CoWQ127bT5H+suN5h2OUIJ7hlB6CwqTKFEMOLPNGtw4T+QQLH1ypIBFVRutv1P1vo vCTC0eCR7wpENOyWc2ay4oLp7qgAnvUPxE6RgcyRYTI+Q2oY0q0tudtNSQsSKOOBnFLe o6ZGOPGroq60eBq/iuHbaT7ixEweBBcKIjlnmRiGsvs5IDBoMbbbTuoREUAI+l6XEin0 PcTOSlOWaB4MOa2DFxUDVckMmMFljZz+UgYk70jaZEwAVMoELxmEAzEP88c+CNJ7ey5O PB/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si6576252ejf.419.2020.08.23.20.18.55; Sun, 23 Aug 2020 20:19:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728140AbgHXDOe (ORCPT + 99 others); Sun, 23 Aug 2020 23:14:34 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:43286 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728107AbgHXDOa (ORCPT ); Sun, 23 Aug 2020 23:14:30 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id B14C54A4A922D3058E65; Mon, 24 Aug 2020 11:14:24 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Mon, 24 Aug 2020 11:14:15 +0800 From: Yang Shen To: , CC: , , , Subject: [PATCH RESEND 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf' Date: Mon, 24 Aug 2020 11:11:43 +0800 Message-ID: <1598238709-58699-5-git-send-email-shenyang39@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1598238709-58699-1-git-send-email-shenyang39@huawei.com> References: <1598238709-58699-1-git-send-email-shenyang39@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Replace 'sprintf' with 'scnprintf' to avoid overrun. Signed-off-by: Yang Shen Reviewed-by: Zhou Wang --- 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