From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mx.groups.io with SMTP id smtpd.web10.8326.1674954874121287962 for ; Sat, 28 Jan 2023 17:14:34 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: huawei.com, ip: 45.249.212.188, mailfrom: xiewenyi2@huawei.com) Received: from kwepemm600004.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4P4Cwp2dzBzJrGw; Sun, 29 Jan 2023 09:12:58 +0800 (CST) Received: from kwephisprg16640.huawei.com (10.247.83.252) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Sun, 29 Jan 2023 09:14:30 +0800 From: "wenyi,xie" To: , , CC: , Subject: [PATCH EDK2 v1 1/1] NetworkPkg/Ip4Dxe:Null-checking before dereference Date: Sun, 29 Jan 2023 09:14:24 +0800 Message-ID: <20230129011424.1716624-2-xiewenyi2@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20230129011424.1716624-1-xiewenyi2@huawei.com> References: <20230129011424.1716624-1-xiewenyi2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.247.83.252] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected Content-Type: text/plain Null-checking first before a pointer is dereferenced. Cc: Maciej Rabeda Cc: Siyuan Fu Signed-off-by: Wenyi Xie --- NetworkPkg/Ip4Dxe/Ip4Config2Nv.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/NetworkPkg/Ip4Dxe/Ip4Config2Nv.c b/NetworkPkg/Ip4Dxe/Ip4Config2Nv.c index e0b6a4d4a92f..b96e11bdabba 100644 --- a/NetworkPkg/Ip4Dxe/Ip4Config2Nv.c +++ b/NetworkPkg/Ip4Dxe/Ip4Config2Nv.c @@ -397,16 +397,16 @@ Ip4Config2ConvertConfigNvDataToIfrNvData ( UINTN DnsCount; EFI_IPv4_ADDRESS *DnsAddress; + if ((IfrNvData == NULL) || (Instance == NULL)) { + return EFI_INVALID_PARAMETER; + } + Status = EFI_SUCCESS; Ip4Config2 = &Instance->Ip4Config2; Ip4Info = NULL; DnsAddress = NULL; GatewaySize = sizeof (EFI_IPv4_ADDRESS); - if ((IfrNvData == NULL) || (Instance == NULL)) { - return EFI_INVALID_PARAMETER; - } - NET_CHECK_SIGNATURE (Instance, IP4_CONFIG2_INSTANCE_SIGNATURE); IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance); @@ -571,6 +571,10 @@ Ip4Config2ConvertIfrNvDataToConfigNvData ( UINTN DataSize; EFI_INPUT_KEY Key; + if ((Instance == NULL) || (IfrFormNvData == NULL)) { + return EFI_INVALID_PARAMETER; + } + Status = EFI_SUCCESS; Ip4Cfg2 = &Instance->Ip4Config2; Ip4NvData = &Instance->Ip4NvData; @@ -581,10 +585,6 @@ Ip4Config2ConvertIfrNvDataToConfigNvData ( TimeoutEvent = NULL; SetAddressEvent = NULL; - if ((Instance == NULL) || (IfrFormNvData == NULL)) { - return EFI_INVALID_PARAMETER; - } - if (IfrFormNvData->Configure != TRUE) { return EFI_SUCCESS; } -- 2.20.1.windows.1