Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1344441ybh; Thu, 23 Jul 2020 06:40:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+fSTB+pB8cMjX9GqpWimN/+l5QuZ2vkDmeVWOODUx07uYg+kGSVsW/h5tquEw37UV2pUm X-Received: by 2002:a17:906:a055:: with SMTP id bg21mr4368902ejb.516.1595511635609; Thu, 23 Jul 2020 06:40:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595511635; cv=none; d=google.com; s=arc-20160816; b=SBnNIffgYcDr9zea9CVMCJEVyOk174kWPXoAFixvU4j5hUaQF1B0Ko0gqTlNPP2bak 1gm1EAP4/oiDyZ4Zq7nNsLxIjVtK5sybhjl2HIJAX7p8+5zHSZ4iBlBBFJ0NenW5xEiA BpNq2BO6YTQZ5iuXhzzciuBK82IxO12kmVaoP59nfQRCbdHOUywwBRIG0icaUS0lwpDs sC1em+4t0KJEVMmeYkw9dCeMVx7H6A023uEvhzRobIbrJWGDAWIruldfBPT3mu5OSm1R qcpt2ZhG8ybWo+ZrHqoTliYqiQfJNCxT+bQuGzvgsocMUU8eRQKelQigjgnUpUhKMJ0u 1N5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=xBLdq93uGEVYrZ99rDCtRGBSkXdT7p8gyUUbInntlPc=; b=WxAROKA4+9HeRZ6pG/gYiiTGbTFpqyDFQB5orOJ2Xx2PdaWej9gMVY3wLyF47EZRAc OLgDZbeyT1W8XXOCjjrv7nUtGdZWT9+c6zsJ51kZDBaDgc2wMLQlForWirut1gW+h7UT ksdPoQJnYZ2Rz1b+OOadPDknTSKK4M2TpZezSQc/ZhAho49KGbaJ8CfI93Hd+TMgQyRT pVU8hO6Icqm/xDO0wMI9jjhJHhSmSGO+Dr7ejExNVw2DKuhqGPp2OLz86PSbsDgv6yRy W97+erOahjFP7Yv4v+W8RBMrhnvzSlXLT3+WryYDCDaHrMrXT+Nm9yJMFbmHYF2qGSdo xS+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 h20si2113673edr.281.2020.07.23.06.40.12; Thu, 23 Jul 2020 06:40:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728951AbgGWNjn (ORCPT + 99 others); Thu, 23 Jul 2020 09:39:43 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:51724 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726521AbgGWNjn (ORCPT ); Thu, 23 Jul 2020 09:39:43 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 184198C5064C6EBF5F84; Thu, 23 Jul 2020 21:39:40 +0800 (CST) Received: from huawei.com (10.175.104.82) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Thu, 23 Jul 2020 21:39:37 +0800 From: Huang Guobin To: , , CC: Subject: [PATCH] lib: Verify array index is correct before using it Date: Thu, 23 Jul 2020 09:48:07 -0400 Message-ID: <20200723134807.35027-1-huangguobin4@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.104.82] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This code reads from the array before verifying that "c" is a valid index. Move test array offset code before use to fix it. Fixes: 2da572c959dd ("lib: add software 842 compression/decompression") Signed-off-by: Huang Guobin --- lib/842/842_compress.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/842/842_compress.c b/lib/842/842_compress.c index c02baa4168e1..10f9f8a0d05b 100644 --- a/lib/842/842_compress.c +++ b/lib/842/842_compress.c @@ -222,12 +222,13 @@ static int add_bits(struct sw842_param *p, u64 d, u8 n) static int add_template(struct sw842_param *p, u8 c) { int ret, i, b = 0; - u8 *t = comp_ops[c]; + u8 *t = NULL; bool inv = false; if (c >= OPS_MAX) return -EINVAL; + t = comp_ops[c]; pr_debug("template %x\n", t[4]); ret = add_bits(p, t[4], OP_BITS); @@ -379,12 +380,14 @@ static int add_end_template(struct sw842_param *p) static bool check_template(struct sw842_param *p, u8 c) { - u8 *t = comp_ops[c]; + u8 *t = NULL; int i, match, b = 0; if (c >= OPS_MAX) return false; + t = comp_ops[c]; + for (i = 0; i < 4; i++) { if (t[i] & OP_ACTION_INDEX) { if (t[i] & OP_AMOUNT_2) -- 2.17.1