From patchwork Fri May 6 13:33:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 12841169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C1D6C433EF for ; Fri, 6 May 2022 13:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243922AbiEFNpo (ORCPT ); Fri, 6 May 2022 09:45:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354797AbiEFNpc (ORCPT ); Fri, 6 May 2022 09:45:32 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A0D92459F for ; Fri, 6 May 2022 06:41:47 -0700 (PDT) Received: from fraeml710-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Kvs9J0W9Sz67xwN; Fri, 6 May 2022 21:39:00 +0800 (CST) Received: from lhreml715-chm.china.huawei.com (10.201.108.66) by fraeml710-chm.china.huawei.com (10.206.15.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 6 May 2022 15:41:45 +0200 Received: from P_UKIT01-A7bmah.china.huawei.com (10.47.73.106) by lhreml715-chm.china.huawei.com (10.201.108.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 6 May 2022 14:41:44 +0100 From: To: , CC: , , , , , , , Subject: [PATCH 10/10] rasdaemon: Fix for a memory out-of-bounds issue and optimized code to remove duplicate function. Date: Fri, 6 May 2022 14:33:07 +0100 Message-ID: <20220506133307.1799-11-shiju.jose@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20220506133307.1799-1-shiju.jose@huawei.com> References: <20220506133307.1799-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.73.106] X-ClientProxiedBy: lhreml744-chm.china.huawei.com (10.201.108.194) To lhreml715-chm.china.huawei.com (10.201.108.66) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org From: Shiju Jose Fixed a memory out-of-bounds issue with string pointers and optimized code structure to remove duplicate function. Signed-off-by: Lei Feng Signed-off-by: Shiju Jose --- non-standard-hisi_hip08.c | 6 +++--- non-standard-hisilicon.c | 2 +- ras-non-standard-handler.c | 16 +--------------- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/non-standard-hisi_hip08.c b/non-standard-hisi_hip08.c index 9092183..4ef47ea 100644 --- a/non-standard-hisi_hip08.c +++ b/non-standard-hisi_hip08.c @@ -1014,15 +1014,15 @@ static int decode_hip08_pcie_local_error(struct ras_events *ras, static struct ras_ns_ev_decoder hip08_ns_ev_decoder[] = { { - .sec_type = "1f8161e155d641e6bd107afd1dc5f7c5", + .sec_type = "1f8161e1-55d6-41e6-bd10-7afd1dc5f7c5", .decode = decode_hip08_oem_type1_error, }, { - .sec_type = "45534ea6ce2341158535e07ab3aef91d", + .sec_type = "45534ea6-ce23-4115-8535-e07ab3aef91d", .decode = decode_hip08_oem_type2_error, }, { - .sec_type = "b2889fc9e7d74f9da867af42e98be772", + .sec_type = "b2889fc9-e7d7-4f9d-a867-af42e98be772", .decode = decode_hip08_pcie_local_error, }, }; diff --git a/non-standard-hisilicon.c b/non-standard-hisilicon.c index d1e1774..6ee9271 100644 --- a/non-standard-hisilicon.c +++ b/non-standard-hisilicon.c @@ -387,7 +387,7 @@ static int decode_hisi_common_section(struct ras_events *ras, static struct ras_ns_ev_decoder hisi_section_ns_ev_decoder[] = { { - .sec_type = "c8b328a899174af69a132e08ab2e7586", + .sec_type = "c8b328a8-9917-4af6-9a13-2e08ab2e7586", .decode = decode_hisi_common_section, }, }; diff --git a/ras-non-standard-handler.c b/ras-non-standard-handler.c index 6d5a6f8..6932e58 100644 --- a/ras-non-standard-handler.c +++ b/ras-non-standard-handler.c @@ -52,20 +52,6 @@ static char *uuid_le(const char *uu) return uuid; } -static int uuid_le_cmp(const char *sec_type, const char *uuid2) -{ - static char uuid1[32]; - char *p = uuid1; - int i; - static const unsigned char le[16] = { - 3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15}; - - for (i = 0; i < 16; i++) - p += sprintf(p, "%.2x", (unsigned char) sec_type[le[i]]); - *p = 0; - return strncmp(uuid1, uuid2, 32); -} - int register_ns_ev_decoder(struct ras_ns_ev_decoder *ns_ev_decoder) { struct ras_ns_ev_decoder *list; @@ -96,7 +82,7 @@ static int find_ns_ev_decoder(const char *sec_type, struct ras_ns_ev_decoder **p ns_ev_decoder = ras_ns_ev_dec_list; while (ns_ev_decoder) { - if (uuid_le_cmp(sec_type, ns_ev_decoder->sec_type) == 0) { + if (strcmp(uuid_le(sec_type), ns_ev_decoder->sec_type) == 0) { *p_ns_ev_dec = ns_ev_decoder; match = 1; break;