It's incorrect to check the value 1(DNS_CLASS_INET) of QClass.
Moreover, the 'Identification' and 'Type' filed in Query packet
should not be changed to little endian since the packet maybe
retransmitted while there is any error happened.

Cc: Ye Ting <[email protected]>
Cc: Zhang Lubo <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <[email protected]>
---
 NetworkPkg/DnsDxe/DnsImpl.c | 29 +++++++++++++++++++++--------
 NetworkPkg/DnsDxe/DnsImpl.h |  2 ++
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/NetworkPkg/DnsDxe/DnsImpl.c b/NetworkPkg/DnsDxe/DnsImpl.c
index 4f10e17..360f68e 100644
--- a/NetworkPkg/DnsDxe/DnsImpl.c
+++ b/NetworkPkg/DnsDxe/DnsImpl.c
@@ -1041,10 +1041,11 @@ AddDns6ServerIp (
   Find out whether the response is valid or invalid.
 
   @param  TokensMap       All DNS transmittal Tokens entry.  
   @param  Identification  Identification for queried packet.  
   @param  Type            Type for queried packet.
+  @param  Class           Class for queried packet.
   @param  Item            Return corresponding Token entry.
 
   @retval TRUE            The response is valid.
   @retval FALSE           The response is invalid.
   
@@ -1052,10 +1053,11 @@ AddDns6ServerIp (
 BOOLEAN
 IsValidDnsResponse (
   IN     NET_MAP      *TokensMap,
   IN     UINT16       Identification,
   IN     UINT16       Type,
+  IN     UINT16       Class,
      OUT NET_MAP_ITEM **Item
   )
 {
   LIST_ENTRY              *Entry;
 
@@ -1075,21 +1077,20 @@ IsValidDnsResponse (
       TxString = NetbufGetByte (Packet, 0, NULL);
       ASSERT (TxString != NULL);
       DnsHeader = (DNS_HEADER *) TxString;
       QueryName = (CHAR8 *) (TxString + sizeof (*DnsHeader));
       QuerySection = (DNS_QUERY_SECTION *) (QueryName + AsciiStrLen 
(QueryName) + 1);
-
-      DnsHeader->Identification = NTOHS (DnsHeader->Identification);
-      QuerySection->Type = NTOHS (QuerySection->Type);
         
-      if (DnsHeader->Identification == Identification && QuerySection->Type == 
Type) {
+      if (NTOHS (DnsHeader->Identification) == Identification &&
+          NTOHS (QuerySection->Type) == Type && 
+          NTOHS (QuerySection->Class) == Class) {
         return TRUE;
       }
     } 
   }
   
-  *Item =NULL;
+  *Item = NULL;
   
   return FALSE;
 }
 
 /**
@@ -1193,19 +1194,31 @@ ParseDnsResponse (
 
   //
   // Check DnsResponse Validity, if so, also get a valid NET_MAP_ITEM.
   //
   if (Instance->Service->IpVersion == IP_VERSION_4) {
-    if (!IsValidDnsResponse (&Instance->Dns4TxTokens, 
DnsHeader->Identification, QuerySection->Type, &Item)) {
+    if (!IsValidDnsResponse (
+           &Instance->Dns4TxTokens, 
+           DnsHeader->Identification, 
+           QuerySection->Type,
+           QuerySection->Class,
+           &Item
+           )) {
       *Completed = FALSE;
       Status = EFI_ABORTED;
       goto ON_EXIT;
     }
     ASSERT (Item != NULL);
     Dns4TokenEntry = (DNS4_TOKEN_ENTRY *) (Item->Key);
   } else {
-    if (!IsValidDnsResponse (&Instance->Dns6TxTokens, 
DnsHeader->Identification, QuerySection->Type, &Item)) {
+    if (!IsValidDnsResponse (
+           &Instance->Dns6TxTokens, 
+           DnsHeader->Identification, 
+           QuerySection->Type,
+           QuerySection->Class,
+           &Item
+           )) {
       *Completed = FALSE;
       Status = EFI_ABORTED;
       goto ON_EXIT;
     }
     ASSERT (Item != NULL);
@@ -1214,11 +1227,11 @@ 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 || QuerySection->Class 
!= DNS_CLASS_INET) {
+      DnsHeader->Flags.Bits.QR != DNS_FLAGS_QR_RESPONSE) {
       Status = EFI_ABORTED;
       goto ON_EXIT;
   }
 
   //
diff --git a/NetworkPkg/DnsDxe/DnsImpl.h b/NetworkPkg/DnsDxe/DnsImpl.h
index 0ef8255..5fa7f24 100644
--- a/NetworkPkg/DnsDxe/DnsImpl.h
+++ b/NetworkPkg/DnsDxe/DnsImpl.h
@@ -559,10 +559,11 @@ AddDns6ServerIp (
   Find out whether the response is valid or invalid.
 
   @param  TokensMap       All DNS transmittal Tokens entry.  
   @param  Identification  Identification for queried packet.  
   @param  Type            Type for queried packet.
+  @param  Class           Class for queried packet.
   @param  Item            Return corresponding Token entry.
 
   @retval TRUE            The response is valid.
   @retval FALSE           The response is invalid.
   
@@ -570,10 +571,11 @@ AddDns6ServerIp (
 BOOLEAN
 IsValidDnsResponse (
   IN     NET_MAP      *TokensMap,
   IN     UINT16       Identification,
   IN     UINT16       Type,
+  IN     UINT16       Class,
      OUT NET_MAP_ITEM **Item
   );
 
 /**
   Parse Dns Response.
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to