Discussion:
[edk2] [Patch 2/2] MdeModulePkg: Code logic optimization for Ip4Dxe driver
Wang Fan
2015-07-10 08:19:09 UTC
Permalink
Move null check before set value to address to avoid null address dereferenced.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: fanwang2 <***@intel.com>
---
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
index 27dae58..381dcb1 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
@@ -872,10 +872,14 @@ Ip4FormExtractConfig (
EFI_STRING ConfigRequest;
BOOLEAN AllocatedRequest;
EFI_STRING FormResult;
UINTN Size;
UINTN BufferSize;
+
+ if (Progress == NULL || Results == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }

Status = EFI_SUCCESS;
IfrFormNvData = NULL;
ConfigRequest = NULL;
FormResult = NULL;
@@ -885,14 +889,10 @@ Ip4FormExtractConfig (
Private = IP4_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(This);
Ip4Config2Instance = IP4_CONFIG2_INSTANCE_FROM_FORM_CALLBACK(Private);
BufferSize = sizeof (IP4_CONFIG2_IFR_NVDATA);
*Progress = Request;

- if (Progress == NULL || Results == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
//
// Check Request data in <ConfigHdr>.
//
if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &gIp4Config2NvDataGuid, mIp4Config2StorageName)) {
IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG2_IFR_NVDATA));
--
1.9.5.msysgit.1
Ye, Ting
2015-07-10 08:33:49 UTC
Permalink
Looks good.
Reviewed-by: Ye Ting <***@intel.com>

-----Original Message-----
From: Wang Fan [mailto:***@intel.com]
Sent: Friday, July 10, 2015 4:19 PM
To: Wu, Jiaxin; Fu, Siyuan; edk2-***@lists.sourceforge.net
Subject: [edk2] [Patch 2/2] MdeModulePkg: Code logic optimization for Ip4Dxe driver

Move null check before set value to address to avoid null address dereferenced.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: fanwang2 <***@intel.com>
---
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
index 27dae58..381dcb1 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
@@ -872,10 +872,14 @@ Ip4FormExtractConfig (
EFI_STRING ConfigRequest;
BOOLEAN AllocatedRequest;
EFI_STRING FormResult;
UINTN Size;
UINTN BufferSize;
+
+ if (Progress == NULL || Results == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }

Status = EFI_SUCCESS;
IfrFormNvData = NULL;
ConfigRequest = NULL;
FormResult = NULL;
@@ -885,14 +889,10 @@ Ip4FormExtractConfig (
Private = IP4_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(This);
Ip4Config2Instance = IP4_CONFIG2_INSTANCE_FROM_FORM_CALLBACK(Private);
BufferSize = sizeof (IP4_CONFIG2_IFR_NVDATA);
*Progress = Request;

- if (Progress == NULL || Results == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
//
// Check Request data in <ConfigHdr>.
//
if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &gIp4Config2NvDataGuid, mIp4Config2StorageName)) {
IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG2_IFR_NVDATA));
--
1.9.5.msysgit.1



------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
edk2-devel mailing list
edk2-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel
Wu, Jiaxin
2015-07-10 08:41:58 UTC
Permalink
Reviewed-by: Jiaxin Wu <***@intel.com>

-----Original Message-----
From: Wang, Fan
Sent: Friday, July 10, 2015 4:19 PM
To: Wu, Jiaxin; Fu, Siyuan; edk2-***@lists.sourceforge.net
Cc: Wang, Fan
Subject: [Patch 2/2] MdeModulePkg: Code logic optimization for Ip4Dxe driver

Move null check before set value to address to avoid null address dereferenced.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: fanwang2 <***@intel.com>
---
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
index 27dae58..381dcb1 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
@@ -872,10 +872,14 @@ Ip4FormExtractConfig (
EFI_STRING ConfigRequest;
BOOLEAN AllocatedRequest;
EFI_STRING FormResult;
UINTN Size;
UINTN BufferSize;
+
+ if (Progress == NULL || Results == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }

Status = EFI_SUCCESS;
IfrFormNvData = NULL;
ConfigRequest = NULL;
FormResult = NULL;
@@ -885,14 +889,10 @@ Ip4FormExtractConfig (
Private = IP4_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(This);
Ip4Config2Instance = IP4_CONFIG2_INSTANCE_FROM_FORM_CALLBACK(Private);
BufferSize = sizeof (IP4_CONFIG2_IFR_NVDATA);
*Progress = Request;

- if (Progress == NULL || Results == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
//
// Check Request data in <ConfigHdr>.
//
if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &gIp4Config2NvDataGuid, mIp4Config2StorageName)) {
IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG2_IFR_NVDATA));
--
1.9.5.msysgit.1
Ard Biesheuvel
2015-07-10 10:49:21 UTC
Permalink
Post by Wang Fan
Move null check before set value to address to avoid null address dereferenced.
Preventing a NULL pointer from being dereferenced is hardly an
optimization, so perhaps you should change the patch description?
Post by Wang Fan
Contributed-under: TianoCore Contribution Agreement 1.0
---
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
index 27dae58..381dcb1 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
@@ -872,10 +872,14 @@ Ip4FormExtractConfig (
EFI_STRING ConfigRequest;
BOOLEAN AllocatedRequest;
EFI_STRING FormResult;
UINTN Size;
UINTN BufferSize;
+
+ if (Progress == NULL || Results == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
Status = EFI_SUCCESS;
IfrFormNvData = NULL;
ConfigRequest = NULL;
FormResult = NULL;
@@ -885,14 +889,10 @@ Ip4FormExtractConfig (
Private = IP4_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(This);
Ip4Config2Instance = IP4_CONFIG2_INSTANCE_FROM_FORM_CALLBACK(Private);
BufferSize = sizeof (IP4_CONFIG2_IFR_NVDATA);
*Progress = Request;
- if (Progress == NULL || Results == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
//
// Check Request data in <ConfigHdr>.
//
if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &gIp4Config2NvDataGuid, mIp4Config2StorageName)) {
IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG2_IFR_NVDATA));
--
1.9.5.msysgit.1
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
edk2-devel mailing list
https://lists.sourceforge.net/lists/listinfo/edk2-devel
Loading...