public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] NetworkPkg: Correct the DNS token return status by RCODE
@ 2016-09-14  6:45 Jiaxin Wu
  2016-09-14 15:04 ` Subramanian, Sriram (EG Servers Platform SW)
  2016-09-19  6:00 ` Hegde, Nagaraj P
  0 siblings, 2 replies; 3+ messages in thread
From: Jiaxin Wu @ 2016-09-14  6:45 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hegde Nagaraj P, Fu Siyuan, Ye Ting

When HostNameToIp() and GeneralLookUp() are called with a invalid
host name, RCODE (4 bit field is set as part of responses) error
will returned in packet to identify the domain name referenced in
the query does not exist. So, EFI_NOT_FOUND should be returned
directly.

Current implementation only check the RCODE in successful condition.
Need update the code for more error check according to RFC 1035 4.1.1
section.

Cc: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
---
 NetworkPkg/DnsDxe/DnsImpl.c | 104 +++++++++++++++++---------------------------
 1 file changed, 40 insertions(+), 64 deletions(-)

diff --git a/NetworkPkg/DnsDxe/DnsImpl.c b/NetworkPkg/DnsDxe/DnsImpl.c
index cfaa4c7..3f3b756 100644
--- a/NetworkPkg/DnsDxe/DnsImpl.c
+++ b/NetworkPkg/DnsDxe/DnsImpl.c
@@ -1230,12 +1230,20 @@ ParseDnsResponse (
   //
   // Continue Check Some Errors.
   //
   if (DnsHeader->Flags.Bits.RCode != DNS_FLAGS_RCODE_NO_ERROR || DnsHeader->AnswersNum < 1 || \
       DnsHeader->Flags.Bits.QR != DNS_FLAGS_QR_RESPONSE) {
-      Status = EFI_ABORTED;
-      goto ON_EXIT;
+    //
+    // The domain name referenced in the query does not exist.
+    //
+    if (DnsHeader->Flags.Bits.RCode == DNS_FLAGS_RCODE_NAME_ERROR) {
+      Status = EFI_NOT_FOUND; 
+    } else {
+      Status = EFI_DEVICE_ERROR;
+    }
+    
+    goto ON_COMPLETE;
   }
   
   //
   // Do some buffer allocations.
   //
@@ -1404,27 +1412,12 @@ ParseDnsResponse (
         
         HostAddr4 = Dns4TokenEntry->Token->RspData.H2AData->IpList;
         AnswerData = (UINT8 *) AnswerSection + sizeof (*AnswerSection);
         CopyMem (&HostAddr4[IpCount], AnswerData, sizeof (EFI_IPv4_ADDRESS));
 
-        //
-        // Update DNS cache dynamically.
-        //
-        if (Dns4CacheEntry != NULL) {
-          if (Dns4CacheEntry->HostName != NULL) {
-            FreePool (Dns4CacheEntry->HostName);
-          }
-
-          if (Dns4CacheEntry->IpAddress != NULL) {
-            FreePool (Dns4CacheEntry->IpAddress);
-          }
-          
-          FreePool (Dns4CacheEntry);
-        }
-
         // 
-        // Allocate new CacheEntry pool.
+        // Allocate new CacheEntry pool to update DNS cache dynamically.
         //
         Dns4CacheEntry = AllocateZeroPool (sizeof (EFI_DNS4_CACHE_ENTRY));
         if (Dns4CacheEntry == NULL) {
           Status = EFI_OUT_OF_RESOURCES;
           goto ON_EXIT;
@@ -1446,11 +1439,23 @@ ParseDnsResponse (
           Dns4CacheEntry->Timeout = MIN (CNameTtl, AnswerSection->Ttl);
         } else {
           Dns4CacheEntry->Timeout = MAX (CNameTtl, AnswerSection->Ttl);
         }
         
-        UpdateDns4Cache (&mDriverData->Dns4CacheList, FALSE, TRUE, *Dns4CacheEntry);  
+        UpdateDns4Cache (&mDriverData->Dns4CacheList, FALSE, TRUE, *Dns4CacheEntry);
+
+        // 
+        // Free allocated CacheEntry pool.
+        //
+        FreePool (Dns4CacheEntry->HostName);
+        Dns4CacheEntry->HostName = NULL;
+        
+        FreePool (Dns4CacheEntry->IpAddress);
+        Dns4CacheEntry->IpAddress = NULL;
+
+        FreePool (Dns4CacheEntry);
+        Dns4CacheEntry = NULL;
 
         IpCount ++;
         Status = EFI_SUCCESS;
         break;
       case DNS_TYPE_AAAA:
@@ -1461,27 +1466,12 @@ ParseDnsResponse (
         
         HostAddr6 = Dns6TokenEntry->Token->RspData.H2AData->IpList;
         AnswerData = (UINT8 *) AnswerSection + sizeof (*AnswerSection);
         CopyMem (&HostAddr6[IpCount], AnswerData, sizeof (EFI_IPv6_ADDRESS));
 
-        //
-        // Update DNS cache dynamically.
-        //
-        if (Dns6CacheEntry != NULL) {
-          if (Dns6CacheEntry->HostName != NULL) {
-            FreePool (Dns6CacheEntry->HostName);
-          }
-
-          if (Dns6CacheEntry->IpAddress != NULL) {
-            FreePool (Dns6CacheEntry->IpAddress);
-          }
-          
-          FreePool (Dns6CacheEntry);
-        }
-
         // 
-        // Allocate new CacheEntry pool.
+        // Allocate new CacheEntry pool to update DNS cache dynamically.
         //
         Dns6CacheEntry = AllocateZeroPool (sizeof (EFI_DNS6_CACHE_ENTRY));
         if (Dns6CacheEntry == NULL) {
           Status = EFI_OUT_OF_RESOURCES;
           goto ON_EXIT;
@@ -1503,11 +1493,23 @@ ParseDnsResponse (
           Dns6CacheEntry->Timeout = MIN (CNameTtl, AnswerSection->Ttl);
         } else {
           Dns6CacheEntry->Timeout = MAX (CNameTtl, AnswerSection->Ttl);
         }
         
-        UpdateDns6Cache (&mDriverData->Dns6CacheList, FALSE, TRUE, *Dns6CacheEntry);  
+        UpdateDns6Cache (&mDriverData->Dns6CacheList, FALSE, TRUE, *Dns6CacheEntry);
+
+        // 
+        // Free allocated CacheEntry pool.
+        //
+        FreePool (Dns6CacheEntry->HostName);
+        Dns6CacheEntry->HostName = NULL;
+        
+        FreePool (Dns6CacheEntry->IpAddress);
+        Dns6CacheEntry->IpAddress = NULL;
+
+        FreePool (Dns6CacheEntry);
+        Dns6CacheEntry = NULL;
         
         IpCount ++;
         Status = EFI_SUCCESS;
         break;
       case DNS_TYPE_CNAME:
@@ -1556,11 +1558,12 @@ ParseDnsResponse (
         Status = EFI_UNSUPPORTED;
         goto ON_EXIT;
       }
     }
   }
-
+  
+ON_COMPLETE:
   //
   // Parsing is complete, free the sending packet and signal Event here.
   //
   if (Item != NULL && Item->Value != NULL) {
     NetbufFree ((NET_BUF *) (Item->Value));
@@ -1582,37 +1585,10 @@ ParseDnsResponse (
       gBS->SignalEvent (Dns6TokenEntry->Token->Event);
       DispatchDpc ();
     }
   }
 
-  // 
-  // Free allocated CacheEntry pool.
-  //
-  if (Dns4CacheEntry != NULL) {
-    if (Dns4CacheEntry->HostName != NULL) {
-      FreePool (Dns4CacheEntry->HostName);
-    }
-
-    if (Dns4CacheEntry->IpAddress != NULL) {
-      FreePool (Dns4CacheEntry->IpAddress);
-    }
-
-    FreePool (Dns4CacheEntry);
-  }
-  
-  if (Dns6CacheEntry != NULL) {
-    if (Dns6CacheEntry->HostName != NULL) {
-      FreePool (Dns6CacheEntry->HostName);
-    }
-
-    if (Dns6CacheEntry->IpAddress != NULL) {
-      FreePool (Dns6CacheEntry->IpAddress);
-    }
-  
-    FreePool (Dns6CacheEntry);
-  }
-
 ON_EXIT:
   gBS->RestoreTPL (OldTpl);
   return Status;
 }
 
-- 
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch] NetworkPkg: Correct the DNS token return status by RCODE
  2016-09-14  6:45 [Patch] NetworkPkg: Correct the DNS token return status by RCODE Jiaxin Wu
@ 2016-09-14 15:04 ` Subramanian, Sriram (EG Servers Platform SW)
  2016-09-19  6:00 ` Hegde, Nagaraj P
  1 sibling, 0 replies; 3+ messages in thread
From: Subramanian, Sriram (EG Servers Platform SW) @ 2016-09-14 15:04 UTC (permalink / raw)
  To: Jiaxin Wu, edk2-devel@lists.01.org; +Cc: Ye Ting, Fu Siyuan

Jiaxin,

-      Status = EFI_ABORTED;
-      goto ON_EXIT;
+    //
+    // The domain name referenced in the query does not exist.
+    //
+    if (DnsHeader->Flags.Bits.RCode == DNS_FLAGS_RCODE_NAME_ERROR) {
+      Status = EFI_NOT_FOUND; 
+    } else {
+      Status = EFI_DEVICE_ERROR;
+    }
+    
+    goto ON_COMPLETE;

This change looks good to me. Thanks for addressing this. Nagaraj is on vacation and will test it early next week and provide feedback.

Reviewed-by: Sriram Subramanian <sriram-s@hpe.com>

Thanks,
Sriram.

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jiaxin Wu
Sent: Wednesday, September 14, 2016 12:16 PM
To: edk2-devel@lists.01.org
Cc: Ye Ting <ting.ye@intel.com>; Fu Siyuan <siyuan.fu@intel.com>
Subject: [edk2] [Patch] NetworkPkg: Correct the DNS token return status by RCODE

When HostNameToIp() and GeneralLookUp() are called with a invalid
host name, RCODE (4 bit field is set as part of responses) error
will returned in packet to identify the domain name referenced in
the query does not exist. So, EFI_NOT_FOUND should be returned
directly.

Current implementation only check the RCODE in successful condition.
Need update the code for more error check according to RFC 1035 4.1.1
section.

Cc: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
---
 NetworkPkg/DnsDxe/DnsImpl.c | 104 +++++++++++++++++---------------------------
 1 file changed, 40 insertions(+), 64 deletions(-)

diff --git a/NetworkPkg/DnsDxe/DnsImpl.c b/NetworkPkg/DnsDxe/DnsImpl.c
index cfaa4c7..3f3b756 100644
--- a/NetworkPkg/DnsDxe/DnsImpl.c
+++ b/NetworkPkg/DnsDxe/DnsImpl.c
@@ -1230,12 +1230,20 @@ ParseDnsResponse (
   //
   // Continue Check Some Errors.
   //
   if (DnsHeader->Flags.Bits.RCode != DNS_FLAGS_RCODE_NO_ERROR || DnsHeader->AnswersNum < 1 || \
       DnsHeader->Flags.Bits.QR != DNS_FLAGS_QR_RESPONSE) {
-      Status = EFI_ABORTED;
-      goto ON_EXIT;
+    //
+    // The domain name referenced in the query does not exist.
+    //
+    if (DnsHeader->Flags.Bits.RCode == DNS_FLAGS_RCODE_NAME_ERROR) {
+      Status = EFI_NOT_FOUND; 
+    } else {
+      Status = EFI_DEVICE_ERROR;
+    }
+    
+    goto ON_COMPLETE;
   }
   
   //
   // Do some buffer allocations.
   //
@@ -1404,27 +1412,12 @@ ParseDnsResponse (
         
         HostAddr4 = Dns4TokenEntry->Token->RspData.H2AData->IpList;
         AnswerData = (UINT8 *) AnswerSection + sizeof (*AnswerSection);
         CopyMem (&HostAddr4[IpCount], AnswerData, sizeof (EFI_IPv4_ADDRESS));
 
-        //
-        // Update DNS cache dynamically.
-        //
-        if (Dns4CacheEntry != NULL) {
-          if (Dns4CacheEntry->HostName != NULL) {
-            FreePool (Dns4CacheEntry->HostName);
-          }
-
-          if (Dns4CacheEntry->IpAddress != NULL) {
-            FreePool (Dns4CacheEntry->IpAddress);
-          }
-          
-          FreePool (Dns4CacheEntry);
-        }
-
         // 
-        // Allocate new CacheEntry pool.
+        // Allocate new CacheEntry pool to update DNS cache dynamically.
         //
         Dns4CacheEntry = AllocateZeroPool (sizeof (EFI_DNS4_CACHE_ENTRY));
         if (Dns4CacheEntry == NULL) {
           Status = EFI_OUT_OF_RESOURCES;
           goto ON_EXIT;
@@ -1446,11 +1439,23 @@ ParseDnsResponse (
           Dns4CacheEntry->Timeout = MIN (CNameTtl, AnswerSection->Ttl);
         } else {
           Dns4CacheEntry->Timeout = MAX (CNameTtl, AnswerSection->Ttl);
         }
         
-        UpdateDns4Cache (&mDriverData->Dns4CacheList, FALSE, TRUE, *Dns4CacheEntry);  
+        UpdateDns4Cache (&mDriverData->Dns4CacheList, FALSE, TRUE, *Dns4CacheEntry);
+
+        // 
+        // Free allocated CacheEntry pool.
+        //
+        FreePool (Dns4CacheEntry->HostName);
+        Dns4CacheEntry->HostName = NULL;
+        
+        FreePool (Dns4CacheEntry->IpAddress);
+        Dns4CacheEntry->IpAddress = NULL;
+
+        FreePool (Dns4CacheEntry);
+        Dns4CacheEntry = NULL;
 
         IpCount ++;
         Status = EFI_SUCCESS;
         break;
       case DNS_TYPE_AAAA:
@@ -1461,27 +1466,12 @@ ParseDnsResponse (
         
         HostAddr6 = Dns6TokenEntry->Token->RspData.H2AData->IpList;
         AnswerData = (UINT8 *) AnswerSection + sizeof (*AnswerSection);
         CopyMem (&HostAddr6[IpCount], AnswerData, sizeof (EFI_IPv6_ADDRESS));
 
-        //
-        // Update DNS cache dynamically.
-        //
-        if (Dns6CacheEntry != NULL) {
-          if (Dns6CacheEntry->HostName != NULL) {
-            FreePool (Dns6CacheEntry->HostName);
-          }
-
-          if (Dns6CacheEntry->IpAddress != NULL) {
-            FreePool (Dns6CacheEntry->IpAddress);
-          }
-          
-          FreePool (Dns6CacheEntry);
-        }
-
         // 
-        // Allocate new CacheEntry pool.
+        // Allocate new CacheEntry pool to update DNS cache dynamically.
         //
         Dns6CacheEntry = AllocateZeroPool (sizeof (EFI_DNS6_CACHE_ENTRY));
         if (Dns6CacheEntry == NULL) {
           Status = EFI_OUT_OF_RESOURCES;
           goto ON_EXIT;
@@ -1503,11 +1493,23 @@ ParseDnsResponse (
           Dns6CacheEntry->Timeout = MIN (CNameTtl, AnswerSection->Ttl);
         } else {
           Dns6CacheEntry->Timeout = MAX (CNameTtl, AnswerSection->Ttl);
         }
         
-        UpdateDns6Cache (&mDriverData->Dns6CacheList, FALSE, TRUE, *Dns6CacheEntry);  
+        UpdateDns6Cache (&mDriverData->Dns6CacheList, FALSE, TRUE, *Dns6CacheEntry);
+
+        // 
+        // Free allocated CacheEntry pool.
+        //
+        FreePool (Dns6CacheEntry->HostName);
+        Dns6CacheEntry->HostName = NULL;
+        
+        FreePool (Dns6CacheEntry->IpAddress);
+        Dns6CacheEntry->IpAddress = NULL;
+
+        FreePool (Dns6CacheEntry);
+        Dns6CacheEntry = NULL;
         
         IpCount ++;
         Status = EFI_SUCCESS;
         break;
       case DNS_TYPE_CNAME:
@@ -1556,11 +1558,12 @@ ParseDnsResponse (
         Status = EFI_UNSUPPORTED;
         goto ON_EXIT;
       }
     }
   }
-
+  
+ON_COMPLETE:
   //
   // Parsing is complete, free the sending packet and signal Event here.
   //
   if (Item != NULL && Item->Value != NULL) {
     NetbufFree ((NET_BUF *) (Item->Value));
@@ -1582,37 +1585,10 @@ ParseDnsResponse (
       gBS->SignalEvent (Dns6TokenEntry->Token->Event);
       DispatchDpc ();
     }
   }
 
-  // 
-  // Free allocated CacheEntry pool.
-  //
-  if (Dns4CacheEntry != NULL) {
-    if (Dns4CacheEntry->HostName != NULL) {
-      FreePool (Dns4CacheEntry->HostName);
-    }
-
-    if (Dns4CacheEntry->IpAddress != NULL) {
-      FreePool (Dns4CacheEntry->IpAddress);
-    }
-
-    FreePool (Dns4CacheEntry);
-  }
-  
-  if (Dns6CacheEntry != NULL) {
-    if (Dns6CacheEntry->HostName != NULL) {
-      FreePool (Dns6CacheEntry->HostName);
-    }
-
-    if (Dns6CacheEntry->IpAddress != NULL) {
-      FreePool (Dns6CacheEntry->IpAddress);
-    }
-  
-    FreePool (Dns6CacheEntry);
-  }
-
 ON_EXIT:
   gBS->RestoreTPL (OldTpl);
   return Status;
 }
 
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch] NetworkPkg: Correct the DNS token return status by RCODE
  2016-09-14  6:45 [Patch] NetworkPkg: Correct the DNS token return status by RCODE Jiaxin Wu
  2016-09-14 15:04 ` Subramanian, Sriram (EG Servers Platform SW)
@ 2016-09-19  6:00 ` Hegde, Nagaraj P
  1 sibling, 0 replies; 3+ messages in thread
From: Hegde, Nagaraj P @ 2016-09-19  6:00 UTC (permalink / raw)
  To: Jiaxin Wu, edk2-devel@lists.01.org; +Cc: Fu Siyuan, Ye Ting

Tested-by: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>

-----Original Message-----
From: Jiaxin Wu [mailto:jiaxin.wu@intel.com] 
Sent: Wednesday, September 14, 2016 12:16 PM
To: edk2-devel@lists.01.org
Cc: Hegde, Nagaraj P <nagaraj-p.hegde@hpe.com>; Fu Siyuan <siyuan.fu@intel.com>; Ye Ting <ting.ye@intel.com>
Subject: [Patch] NetworkPkg: Correct the DNS token return status by RCODE

When HostNameToIp() and GeneralLookUp() are called with a invalid
host name, RCODE (4 bit field is set as part of responses) error
will returned in packet to identify the domain name referenced in
the query does not exist. So, EFI_NOT_FOUND should be returned
directly.

Current implementation only check the RCODE in successful condition.
Need update the code for more error check according to RFC 1035 4.1.1
section.

Cc: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
---
 NetworkPkg/DnsDxe/DnsImpl.c | 104 +++++++++++++++++---------------------------
 1 file changed, 40 insertions(+), 64 deletions(-)

diff --git a/NetworkPkg/DnsDxe/DnsImpl.c b/NetworkPkg/DnsDxe/DnsImpl.c
index cfaa4c7..3f3b756 100644
--- a/NetworkPkg/DnsDxe/DnsImpl.c
+++ b/NetworkPkg/DnsDxe/DnsImpl.c
@@ -1230,12 +1230,20 @@ ParseDnsResponse (
   //
   // Continue Check Some Errors.
   //
   if (DnsHeader->Flags.Bits.RCode != DNS_FLAGS_RCODE_NO_ERROR || DnsHeader->AnswersNum < 1 || \
       DnsHeader->Flags.Bits.QR != DNS_FLAGS_QR_RESPONSE) {
-      Status = EFI_ABORTED;
-      goto ON_EXIT;
+    //
+    // The domain name referenced in the query does not exist.
+    //
+    if (DnsHeader->Flags.Bits.RCode == DNS_FLAGS_RCODE_NAME_ERROR) {
+      Status = EFI_NOT_FOUND; 
+    } else {
+      Status = EFI_DEVICE_ERROR;
+    }
+    
+    goto ON_COMPLETE;
   }
   
   //
   // Do some buffer allocations.
   //
@@ -1404,27 +1412,12 @@ ParseDnsResponse (
         
         HostAddr4 = Dns4TokenEntry->Token->RspData.H2AData->IpList;
         AnswerData = (UINT8 *) AnswerSection + sizeof (*AnswerSection);
         CopyMem (&HostAddr4[IpCount], AnswerData, sizeof (EFI_IPv4_ADDRESS));
 
-        //
-        // Update DNS cache dynamically.
-        //
-        if (Dns4CacheEntry != NULL) {
-          if (Dns4CacheEntry->HostName != NULL) {
-            FreePool (Dns4CacheEntry->HostName);
-          }
-
-          if (Dns4CacheEntry->IpAddress != NULL) {
-            FreePool (Dns4CacheEntry->IpAddress);
-          }
-          
-          FreePool (Dns4CacheEntry);
-        }
-
         // 
-        // Allocate new CacheEntry pool.
+        // Allocate new CacheEntry pool to update DNS cache dynamically.
         //
         Dns4CacheEntry = AllocateZeroPool (sizeof (EFI_DNS4_CACHE_ENTRY));
         if (Dns4CacheEntry == NULL) {
           Status = EFI_OUT_OF_RESOURCES;
           goto ON_EXIT;
@@ -1446,11 +1439,23 @@ ParseDnsResponse (
           Dns4CacheEntry->Timeout = MIN (CNameTtl, AnswerSection->Ttl);
         } else {
           Dns4CacheEntry->Timeout = MAX (CNameTtl, AnswerSection->Ttl);
         }
         
-        UpdateDns4Cache (&mDriverData->Dns4CacheList, FALSE, TRUE, *Dns4CacheEntry);  
+        UpdateDns4Cache (&mDriverData->Dns4CacheList, FALSE, TRUE, *Dns4CacheEntry);
+
+        // 
+        // Free allocated CacheEntry pool.
+        //
+        FreePool (Dns4CacheEntry->HostName);
+        Dns4CacheEntry->HostName = NULL;
+        
+        FreePool (Dns4CacheEntry->IpAddress);
+        Dns4CacheEntry->IpAddress = NULL;
+
+        FreePool (Dns4CacheEntry);
+        Dns4CacheEntry = NULL;
 
         IpCount ++;
         Status = EFI_SUCCESS;
         break;
       case DNS_TYPE_AAAA:
@@ -1461,27 +1466,12 @@ ParseDnsResponse (
         
         HostAddr6 = Dns6TokenEntry->Token->RspData.H2AData->IpList;
         AnswerData = (UINT8 *) AnswerSection + sizeof (*AnswerSection);
         CopyMem (&HostAddr6[IpCount], AnswerData, sizeof (EFI_IPv6_ADDRESS));
 
-        //
-        // Update DNS cache dynamically.
-        //
-        if (Dns6CacheEntry != NULL) {
-          if (Dns6CacheEntry->HostName != NULL) {
-            FreePool (Dns6CacheEntry->HostName);
-          }
-
-          if (Dns6CacheEntry->IpAddress != NULL) {
-            FreePool (Dns6CacheEntry->IpAddress);
-          }
-          
-          FreePool (Dns6CacheEntry);
-        }
-
         // 
-        // Allocate new CacheEntry pool.
+        // Allocate new CacheEntry pool to update DNS cache dynamically.
         //
         Dns6CacheEntry = AllocateZeroPool (sizeof (EFI_DNS6_CACHE_ENTRY));
         if (Dns6CacheEntry == NULL) {
           Status = EFI_OUT_OF_RESOURCES;
           goto ON_EXIT;
@@ -1503,11 +1493,23 @@ ParseDnsResponse (
           Dns6CacheEntry->Timeout = MIN (CNameTtl, AnswerSection->Ttl);
         } else {
           Dns6CacheEntry->Timeout = MAX (CNameTtl, AnswerSection->Ttl);
         }
         
-        UpdateDns6Cache (&mDriverData->Dns6CacheList, FALSE, TRUE, *Dns6CacheEntry);  
+        UpdateDns6Cache (&mDriverData->Dns6CacheList, FALSE, TRUE, *Dns6CacheEntry);
+
+        // 
+        // Free allocated CacheEntry pool.
+        //
+        FreePool (Dns6CacheEntry->HostName);
+        Dns6CacheEntry->HostName = NULL;
+        
+        FreePool (Dns6CacheEntry->IpAddress);
+        Dns6CacheEntry->IpAddress = NULL;
+
+        FreePool (Dns6CacheEntry);
+        Dns6CacheEntry = NULL;
         
         IpCount ++;
         Status = EFI_SUCCESS;
         break;
       case DNS_TYPE_CNAME:
@@ -1556,11 +1558,12 @@ ParseDnsResponse (
         Status = EFI_UNSUPPORTED;
         goto ON_EXIT;
       }
     }
   }
-
+  
+ON_COMPLETE:
   //
   // Parsing is complete, free the sending packet and signal Event here.
   //
   if (Item != NULL && Item->Value != NULL) {
     NetbufFree ((NET_BUF *) (Item->Value));
@@ -1582,37 +1585,10 @@ ParseDnsResponse (
       gBS->SignalEvent (Dns6TokenEntry->Token->Event);
       DispatchDpc ();
     }
   }
 
-  // 
-  // Free allocated CacheEntry pool.
-  //
-  if (Dns4CacheEntry != NULL) {
-    if (Dns4CacheEntry->HostName != NULL) {
-      FreePool (Dns4CacheEntry->HostName);
-    }
-
-    if (Dns4CacheEntry->IpAddress != NULL) {
-      FreePool (Dns4CacheEntry->IpAddress);
-    }
-
-    FreePool (Dns4CacheEntry);
-  }
-  
-  if (Dns6CacheEntry != NULL) {
-    if (Dns6CacheEntry->HostName != NULL) {
-      FreePool (Dns6CacheEntry->HostName);
-    }
-
-    if (Dns6CacheEntry->IpAddress != NULL) {
-      FreePool (Dns6CacheEntry->IpAddress);
-    }
-  
-    FreePool (Dns6CacheEntry);
-  }
-
 ON_EXIT:
   gBS->RestoreTPL (OldTpl);
   return Status;
 }
 
-- 
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-19  6:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-14  6:45 [Patch] NetworkPkg: Correct the DNS token return status by RCODE Jiaxin Wu
2016-09-14 15:04 ` Subramanian, Sriram (EG Servers Platform SW)
2016-09-19  6:00 ` Hegde, Nagaraj P

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox