From nobody Thu May 2 03:36:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1514946728776463.6103117686523; Tue, 2 Jan 2018 18:32:08 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9BFE6222A54DC; Tue, 2 Jan 2018 18:27:04 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E0B83222A54C3 for ; Tue, 2 Jan 2018 18:27:02 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jan 2018 18:32:05 -0800 Received: from fanwang2-hp.ccr.corp.intel.com ([10.239.9.33]) by orsmga001.jf.intel.com with ESMTP; 02 Jan 2018 18:32:04 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=fan.wang@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,500,1508828400"; d="scan'208";a="20931414" From: fanwang2 To: edk2-devel@lists.01.org Date: Wed, 3 Jan 2018 10:31:49 +0800 Message-Id: <1514946711-4056-2-git-send-email-fan.wang@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1514946711-4056-1-git-send-email-fan.wang@intel.com> References: <1514946711-4056-1-git-send-email-fan.wang@intel.com> Subject: [edk2] [Patch 1/3] MdeModulePkg/DxeNetLib: Fix a potential issue in macro definition. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Wang Fan , Fu Siyuan , Jiaxin Wu MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Wang Fan The NIC_ITEM_CONFIG_SIZE macro in DxeNetLib is defined as: sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE. This macro should be surrounded with parenthesis to avoid being incorrectly used. Cc: Fu Siyuan Cc: Ye Ting Cc: Jiaxin Wu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wang Fan Reviewed-by: Jiaxin Wu --- MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Libr= ary/DxeNetLib/DxeNetLib.c index 26a80a7..0f00f79 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c @@ -36,11 +36,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. #include #include #include #include =20 -#define NIC_ITEM_CONFIG_SIZE sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_= IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE +#define NIC_ITEM_CONFIG_SIZE (sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI= _IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE) #define DEFAULT_ZERO_START ((UINTN) ~0) =20 // // All the supported IP4 maskes in host byte order. // --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 03:36:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1514946731202949.2107120736454; Tue, 2 Jan 2018 18:32:11 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id F34F8222A54E1; Tue, 2 Jan 2018 18:27:06 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7C79E222A54C3 for ; Tue, 2 Jan 2018 18:27:05 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jan 2018 18:32:08 -0800 Received: from fanwang2-hp.ccr.corp.intel.com ([10.239.9.33]) by orsmga001.jf.intel.com with ESMTP; 02 Jan 2018 18:32:06 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=fan.wang@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,500,1508828400"; d="scan'208";a="20931422" From: fanwang2 To: edk2-devel@lists.01.org Date: Wed, 3 Jan 2018 10:31:50 +0800 Message-Id: <1514946711-4056-3-git-send-email-fan.wang@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1514946711-4056-1-git-send-email-fan.wang@intel.com> References: <1514946711-4056-1-git-send-email-fan.wang@intel.com> Subject: [edk2] [Patch 2/3] MdeModulePkg/DxeNetLib: Add parameter check and ASSERT handling. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Wang Fan , Fu Siyuan , Jiaxin Wu MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Wang Fan * Library API should check the input parameters before use, or ASSERT to tell it has to meet some requirements. But in DxeNetLib, not all functions follows this rule. * ASSERT shouldn't be used as error handling, add some handling code for errors. * Add some ASSERT commence in function notes. Cc: Fu Siyuan Cc: Ye Ting Cc: Jiaxin Wu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wang Fan Reviewed-by: Jiaxin Wu --- MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 119 +++++++++++++++++++++++++= ---- 1 file changed, 105 insertions(+), 14 deletions(-) diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Libr= ary/DxeNetLib/DxeNetLib.c index 0f00f79..90f17b7 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c @@ -1,9 +1,9 @@ /** @file Network library. =20 -Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD = License which accompanies this distribution. The full text of the license may be = found at http://opensource.org/licenses/bsd-license.php @@ -196,10 +196,11 @@ SyslogLocateSnp ( Transmit a syslog packet synchronously through SNP. The Packet already has the ethernet header prepended. This function should fill in the source MAC because it will try to locate a SNP each time it is called to avoid the problem if SNP is unloaded. This code snip is copied from MNP. + If Packet is NULL, then ASSERT(). =20 @param[in] Packet The Syslog packet @param[in] Length The length of the packet =20 @retval EFI_DEVICE_ERROR Failed to locate a usable SNP protocol @@ -217,10 +218,12 @@ SyslogSendPacket ( ETHER_HEAD *Ether; EFI_STATUS Status; EFI_EVENT TimeoutEvent; UINT8 *TxBuf; =20 + ASSERT (Packet !=3D NULL); + Snp =3D SyslogLocateSnp (); =20 if (Snp =3D=3D NULL) { return EFI_DEVICE_ERROR; } @@ -308,11 +311,11 @@ ON_EXIT: @param[in] Line The line of code in the File that contains the cur= rent log @param[in] Message The log message @param[in] BufLen The lenght of the Buf @param[out] Buf The buffer to put the packet data =20 - @return The length of the syslog packet built. + @return The length of the syslog packet built, 0 represents no packet is= built. =20 **/ UINT32 SyslogBuildPacket ( IN UINT32 Level, @@ -322,10 +325,11 @@ SyslogBuildPacket ( IN UINT8 *Message, IN UINT32 BufLen, OUT CHAR8 *Buf ) { + EFI_STATUS Status; ETHER_HEAD *Ether; IP4_HEAD *Ip4; EFI_UDP_HEADER *Udp4; EFI_TIME Time; UINT32 Pri; @@ -377,12 +381,14 @@ SyslogBuildPacket ( =20 // // Build the syslog message body with Timestamp machine module Me= ssage // Pri =3D ((NET_SYSLOG_FACILITY & 31) << 3) | (Level & 7); - gRT->GetTime (&Time, NULL); - ASSERT ((Time.Month <=3D 12) && (Time.Month >=3D 1)); + Status =3D gRT->GetTime (&Time, NULL); + if (EFI_ERROR (Status)) { + return 0; + } =20 // // Use %a to format the ASCII strings, %s to format UNICODE strings // Len =3D 0; @@ -437,10 +443,12 @@ SyslogBuildPacket ( __FILE__, __LINE__, NetDebugASPrint ("State transit to %a\n", Name) ) =20 + If Format is NULL, then ASSERT(). + @param Format The ASCII format string. @param ... The variable length parameter whose format is determined by the Format string. =20 @return The buffer containing the formatted message, @@ -455,10 +463,12 @@ NetDebugASPrint ( ) { VA_LIST Marker; CHAR8 *Buf; =20 + ASSERT (Format !=3D NULL); + Buf =3D (CHAR8 *) AllocatePool (NET_DEBUG_MSG_LEN); =20 if (Buf =3D=3D NULL) { return NULL; } @@ -481,11 +491,12 @@ NetDebugASPrint ( @param File The file that contains the log. @param Line The exact line that contains the log. @param Message The user message to log. =20 @retval EFI_INVALID_PARAMETER Any input parameter is invalid. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the packet + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the packet. + @retval EFI_DEVICE_ERROR Device error occurs. @retval EFI_SUCCESS The log is discard because that it is more= verbose than the mNetDebugLevelMax. Or, it has bee= n sent out. **/ EFI_STATUS EFIAPI @@ -502,11 +513,11 @@ NetDebugOutput ( EFI_STATUS Status; =20 // // Check whether the message should be sent out // - if (Message =3D=3D NULL) { + if (Message =3D=3D NULL || File =3D=3D NULL || Module =3D=3D NULL) { return EFI_INVALID_PARAMETER; } =20 if (Level > mNetDebugLevelMax) { Status =3D EFI_SUCCESS; @@ -535,13 +546,17 @@ NetDebugOutput ( Line, Message, NET_SYSLOG_PACKET_LEN, Packet ); + if (Len =3D=3D 0) { + Status =3D EFI_DEVICE_ERROR; + } else { + mSyslogPacketSeq++; + Status =3D SyslogSendPacket (Packet, Len); + } =20 - mSyslogPacketSeq++; - Status =3D SyslogSendPacket (Packet, Len); FreePool (Packet); =20 ON_EXIT: FreePool (Message); return Status; @@ -673,10 +688,12 @@ NetIp4IsUnicast ( } =20 /** Check whether the incoming IPv6 address is a valid unicast address. =20 + ASSERT if Ip6 is NULL. + If the address is a multicast address has binary 0xFF at the start, it i= s not a valid unicast address. If the address is unspecified ::, it is not a v= alid unicast address to be assigned to any node. If the address is loopback a= ddress ::1, it is also not a valid unicast address to be assigned to any physic= al interface. @@ -693,10 +710,12 @@ NetIp6IsValidUnicast ( ) { UINT8 Byte; UINT8 Index; =20 + ASSERT (Ip6 !=3D NULL); + if (Ip6->Addr[0] =3D=3D 0xFF) { return FALSE; } =20 for (Index =3D 0; Index < 15; Index++) { @@ -715,10 +734,12 @@ NetIp6IsValidUnicast ( } =20 /** Check whether the incoming Ipv6 address is the unspecified address or no= t. =20 + ASSERT if Ip6 is NULL. + @param[in] Ip6 - Ip6 address, in network order. =20 @retval TRUE - Yes, unspecified @retval FALSE - No =20 @@ -729,10 +750,12 @@ NetIp6IsUnspecifiedAddr ( IN EFI_IPv6_ADDRESS *Ip6 ) { UINT8 Index; =20 + ASSERT (Ip6 !=3D NULL); + for (Index =3D 0; Index < 16; Index++) { if (Ip6->Addr[Index] !=3D 0) { return FALSE; } } @@ -741,10 +764,12 @@ NetIp6IsUnspecifiedAddr ( } =20 /** Check whether the incoming Ipv6 address is a link-local address. =20 + ASSERT if Ip6 is NULL. + @param[in] Ip6 - Ip6 address, in network order. =20 @retval TRUE - Yes, link-local address @retval FALSE - No =20 @@ -777,10 +802,13 @@ NetIp6IsLinkLocalAddr ( } =20 /** Check whether the Ipv6 address1 and address2 are on the connected networ= k. =20 + ASSERT if Ip1 or Ip2 is NULL. + ASSERT if PrefixLength exceeds IP6_PREFIX_MAX. + @param[in] Ip1 - Ip6 address1, in network order. @param[in] Ip2 - Ip6 address2, in network order. @param[in] PrefixLength - The prefix length of the checking net. =20 @retval TRUE - Yes, connected. @@ -813,11 +841,10 @@ NetIp6IsNetEqual ( } =20 if (Bit > 0) { Mask =3D (UINT8) (0xFF << (8 - Bit)); =20 - ASSERT (Byte < 16); if ((Ip1->Addr[Byte] & Mask) !=3D (Ip2->Addr[Byte] & Mask)) { return FALSE; } } =20 @@ -826,10 +853,12 @@ NetIp6IsNetEqual ( =20 =20 /** Switches the endianess of an IPv6 address =20 + ASSERT if Ip6 is NULL. + This function swaps the bytes in a 128-bit IPv6 address to switch the va= lue from little endian to big endian or vice versa. The byte swapped value is returned. =20 @param Ip6 Points to an IPv6 address @@ -844,10 +873,12 @@ Ip6Swap128 ( ) { UINT64 High; UINT64 Low; =20 + ASSERT (Ip6 !=3D NULL); + CopyMem (&High, Ip6, sizeof (UINT64)); CopyMem (&Low, &Ip6->Addr[8], sizeof (UINT64)); =20 High =3D SwapBytes64 (High); Low =3D SwapBytes64 (Low); @@ -891,10 +922,12 @@ NetRandomInitSeed ( =20 =20 /** Extract a UINT32 from a byte stream. =20 + ASSERT if Buf is NULL. + Copy a UINT32 from a byte stream, then converts it from Network byte order to host byte order. Use this function to avoid alignment erro= r. =20 @param[in] Buf The buffer to extract the UINT32. =20 @@ -907,18 +940,22 @@ NetGetUint32 ( IN UINT8 *Buf ) { UINT32 Value; =20 + ASSERT (Buf !=3D NULL); + CopyMem (&Value, Buf, sizeof (UINT32)); return NTOHL (Value); } =20 =20 /** Put a UINT32 to the byte stream in network byte order. =20 + ASSERT if Buf is NULL. + Converts a UINT32 from host byte order to network byte order. Then copy = it to the byte stream. =20 @param[in, out] Buf The buffer to put the UINT32. @param[in] Data The data to be converted and put into the = byte stream. @@ -929,10 +966,12 @@ EFIAPI NetPutUint32 ( IN OUT UINT8 *Buf, IN UINT32 Data ) { + ASSERT (Buf !=3D NULL); + Data =3D HTONL (Data); CopyMem (Buf, &Data, sizeof (UINT32)); } =20 =20 @@ -1027,10 +1066,12 @@ NetListRemoveTail ( =20 =20 /** Insert a new node entry after a designated node entry of a doubly linked= list. =20 + ASSERT if PrevEntry or NewEntry is NULL. + Inserts a new node entry donated by NewEntry after the node entry donate= d by PrevEntry of the doubly linked list. =20 @param[in, out] PrevEntry The previous entry to insert afte= r. @param[in, out] NewEntry The new entry to insert. @@ -1041,20 +1082,24 @@ EFIAPI NetListInsertAfter ( IN OUT LIST_ENTRY *PrevEntry, IN OUT LIST_ENTRY *NewEntry ) { + ASSERT (PrevEntry !=3D NULL && NewEntry !=3D NULL); + NewEntry->BackLink =3D PrevEntry; NewEntry->ForwardLink =3D PrevEntry->ForwardLink; PrevEntry->ForwardLink->BackLink =3D NewEntry; PrevEntry->ForwardLink =3D NewEntry; } =20 =20 /** Insert a new node entry before a designated node entry of a doubly linke= d list. =20 + ASSERT if PostEntry or NewEntry is NULL. + Inserts a new node entry donated by NewEntry after the node entry donate= d by PostEntry of the doubly linked list. =20 @param[in, out] PostEntry The entry to insert before. @param[in, out] NewEntry The new entry to insert. @@ -1065,10 +1110,12 @@ EFIAPI NetListInsertBefore ( IN OUT LIST_ENTRY *PostEntry, IN OUT LIST_ENTRY *NewEntry ) { + ASSERT (PostEntry !=3D NULL && NewEntry !=3D NULL); + NewEntry->ForwardLink =3D PostEntry; NewEntry->BackLink =3D PostEntry->BackLink; PostEntry->BackLink->ForwardLink =3D NewEntry; PostEntry->BackLink =3D NewEntry; } @@ -1263,11 +1310,10 @@ NetMapClean ( =20 If the number of the pairs in the netmap is zero, return TR= UE. =20 If Map is NULL, then ASSERT(). =20 - @param[in] Map The net map to test. =20 @return TRUE if the netmap is empty, otherwise FALSE. =20 **/ @@ -1283,10 +1329,12 @@ NetMapIsEmpty ( =20 =20 /** Return the number of the pairs in the netmap. =20 + If Map is NULL, then ASSERT(). + @param[in] Map The netmap to get the entry number. =20 @return The entry number in the netmap. =20 **/ @@ -1294,10 +1342,11 @@ UINTN EFIAPI NetMapGetCount ( IN NET_MAP *Map ) { + ASSERT (Map !=3D NULL); return Map->Count; } =20 =20 /** @@ -1358,10 +1407,11 @@ NetMapAllocItem ( Allocate an item to save the pair and add corresponding nod= e entry to the beginning of the Used doubly linked list. The number of the pairs in the netmap increase by 1. =20 If Map is NULL, then ASSERT(). + If Key is NULL, then ASSERT(). =20 @param[in, out] Map The netmap to insert into. @param[in] Key The user's key. @param[in] Value The user's value for the key. =20 @@ -1377,11 +1427,11 @@ NetMapInsertHead ( IN VOID *Value OPTIONAL ) { NET_MAP_ITEM *Item; =20 - ASSERT (Map !=3D NULL); + ASSERT (Map !=3D NULL && Key !=3D NULL); =20 Item =3D NetMapAllocItem (Map); =20 if (Item =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; @@ -1402,10 +1452,11 @@ NetMapInsertHead ( Allocate an item to save the pair and add corresponding nod= e entry to the tail of the Used doubly linked list. The number of the pairs in the netmap increase by 1. =20 If Map is NULL, then ASSERT(). + If Key is NULL, then ASSERT(). =20 @param[in, out] Map The netmap to insert into. @param[in] Key The user's key. @param[in] Value The user's value for the key. =20 @@ -1421,11 +1472,11 @@ NetMapInsertTail ( IN VOID *Value OPTIONAL ) { NET_MAP_ITEM *Item; =20 - ASSERT (Map !=3D NULL); + ASSERT (Map !=3D NULL && Key !=3D NULL); =20 Item =3D NetMapAllocItem (Map); =20 if (Item =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; @@ -1442,10 +1493,13 @@ NetMapInsertTail ( =20 =20 /** Check whether the item is in the Map and return TRUE if it is. =20 + If Map is NULL, then ASSERT(). + If Item is NULL, then ASSERT(). + @param[in] Map The netmap to search within. @param[in] Item The item to search. =20 @return TRUE if the item is in the netmap, otherwise FALSE. =20 @@ -1456,10 +1510,12 @@ NetItemInMap ( IN NET_MAP_ITEM *Item ) { LIST_ENTRY *ListEntry; =20 + ASSERT (Map !=3D NULL && Item !=3D NULL); + NET_LIST_FOR_EACH (ListEntry, &Map->Used) { if (ListEntry =3D=3D &Item->Link) { return TRUE; } } @@ -1473,10 +1529,11 @@ NetItemInMap ( =20 Iterate the Used doubly linked list of the netmap to get every item. Com= pare the key of every item with the key to search. It returns the point to the item contains t= he Key if found. =20 If Map is NULL, then ASSERT(). + If Key is NULL, then ASSERT(). =20 @param[in] Map The netmap to search within. @param[in] Key The key to search. =20 @return The point to the item contains the Key, or NULL if Key isn't in = the map. @@ -1490,11 +1547,11 @@ NetMapFindKey ( ) { LIST_ENTRY *Entry; NET_MAP_ITEM *Item; =20 - ASSERT (Map !=3D NULL); + ASSERT (Map !=3D NULL && Key !=3D NULL); =20 NET_LIST_FOR_EACH (Entry, &Map->Used) { Item =3D NET_LIST_USER_STRUCT (Entry, NET_MAP_ITEM, Link); =20 if (Item->Key =3D=3D Key) { @@ -2093,10 +2150,13 @@ NetLibGetVlanHandle ( } =20 /** Get MAC address associated with the network service handle. =20 + If MacAddress is NULL, then ASSERT(). + If AddressSize is NULL, then ASSERT(). + There should be MNP Service Binding Protocol installed on the input Serv= iceHandle. If SNP is installed on the ServiceHandle or its parent handle, MAC addre= ss will be retrieved from SNP. If no SNP found, try to get SNP mode data use MNP. =20 @param[in] ServiceHandle The handle where network service binding p= rotocols are @@ -2197,10 +2257,12 @@ NetLibGetMacAddress ( =20 /** Convert MAC address of the NIC associated with specified Service Binding= Handle to a unicode string. Callers are responsible for freeing the string stor= age. =20 + If MacString is NULL, then ASSERT(). + Locate simple network protocol associated with the Service Binding Handl= e and get the mac address from SNP. Then convert the mac address into a unicode string. It takes 2 unicode characters to represent a 1 byte binary buffe= r. Plus one unicode character for the null-terminator. =20 @@ -2296,10 +2358,12 @@ NetLibGetMacString ( } =20 /** Detect media status for specified network device. =20 + If MediaPresent is NULL, then ASSERT(). + The underlying UNDI driver may or may not support reporting media status= from GET_STATUS command (PXE_STATFLAGS_GET_STATUS_NO_MEDIA_SUPPORTED). This r= outine will try to invoke Snp->GetStatus() to get the media status: if media al= ready present, it return directly; if media not present, it will stop SNP and = then restart SNP to get the latest media status, this give chance to get the = correct @@ -2404,10 +2468,14 @@ NetLibDetectMedia ( MCastFilter =3D AllocateCopyPool ( MCastFilterCount * sizeof (EFI_MAC_ADDRESS), Snp->Mode->MCastFilter ); ASSERT (MCastFilter !=3D NULL); + if (MCastFilter =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Exit; + } =20 ResetMCastFilters =3D FALSE; } =20 // @@ -2735,10 +2803,12 @@ ON_EXIT: } =20 /** Create an IPv4 device path node. =20 + If Node is NULL, then ASSERT(). + The header type of IPv4 device path node is MESSAGING_DEVICE_PATH. The header subtype of IPv4 device path node is MSG_IPv4_DP. Get other info from parameters to make up the whole IPv4 device path nod= e. =20 @param[in, out] Node Pointer to the IPv4 device path n= ode. @@ -2762,10 +2832,12 @@ NetLibCreateIPv4DPathNode ( IN UINT16 RemotePort, IN UINT16 Protocol, IN BOOLEAN UseDefaultAddress ) { + ASSERT (Node !=3D NULL); + Node->Header.Type =3D MESSAGING_DEVICE_PATH; Node->Header.SubType =3D MSG_IPv4_DP; SetDevicePathNodeLength (&Node->Header, sizeof (IPv4_DEVICE_PATH)); =20 CopyMem (&Node->LocalIpAddress, &LocalIp, sizeof (EFI_IPv4_ADDRESS)); @@ -2792,10 +2864,14 @@ NetLibCreateIPv4DPathNode ( } =20 /** Create an IPv6 device path node. =20 + If Node is NULL, then ASSERT(). + If LocalIp is NULL, then ASSERT(). + If RemoteIp is NULL, then ASSERT(). + The header type of IPv6 device path node is MESSAGING_DEVICE_PATH. The header subtype of IPv6 device path node is MSG_IPv6_DP. Get other info from parameters to make up the whole IPv6 device path nod= e. =20 @param[in, out] Node Pointer to the IPv6 device path n= ode. @@ -2817,10 +2893,12 @@ NetLibCreateIPv6DPathNode ( IN EFI_IPv6_ADDRESS *RemoteIp, IN UINT16 RemotePort, IN UINT16 Protocol ) { + ASSERT (Node !=3D NULL && LocalIp !=3D NULL && RemoteIp !=3D NULL); + Node->Header.Type =3D MESSAGING_DEVICE_PATH; Node->Header.SubType =3D MSG_IPv6_DP; SetDevicePathNodeLength (&Node->Header, sizeof (IPv6_DEVICE_PATH)); =20 CopyMem (&Node->LocalIpAddress, LocalIp, sizeof (EFI_IPv6_ADDRESS)); @@ -2841,10 +2919,12 @@ NetLibCreateIPv6DPathNode ( } =20 /** Find the UNDI/SNP handle from controller and protocol GUID. =20 + If ProtocolGuid is NULL, then ASSERT(). + For example, IP will open a MNP child to transmit/receive packets, when MNP is stopped, IP should also be stopped. IP needs to find its own private data which is related the IP's service binding instance that is install on UNDI/SNP handle. Now, the controller is either a MNP or ARP child handle. But @@ -2868,10 +2948,12 @@ NetLibGetNicHandle ( EFI_HANDLE Handle; EFI_STATUS Status; UINTN OpenCount; UINTN Index; =20 + ASSERT (ProtocolGuid !=3D NULL); + Status =3D gBS->OpenProtocolInformation ( Controller, ProtocolGuid, &OpenBuffer, &OpenCount @@ -3149,10 +3231,12 @@ NetLibIp6ToStr ( } =20 /** This function obtains the system guid from the smbios table. =20 + If SystemGuid is NULL, then ASSERT(). + @param[out] SystemGuid The pointer of the returned system guid. =20 @retval EFI_SUCCESS Successfully obtained the system guid. @retval EFI_NOT_FOUND Did not find the SMBIOS table. =20 @@ -3168,10 +3252,12 @@ NetLibGetSystemGuid ( SMBIOS_TABLE_3_0_ENTRY_POINT *Smbios30Table; SMBIOS_STRUCTURE_POINTER Smbios; SMBIOS_STRUCTURE_POINTER SmbiosEnd; CHAR8 *String; =20 + ASSERT (SystemGuid !=3D NULL); + SmbiosTable =3D NULL; Status =3D EfiGetSystemConfigurationTable (&gEfiSmbios3TableGuid, (VOID = **) &Smbios30Table); if (!(EFI_ERROR (Status) || Smbios30Table =3D=3D NULL)) { Smbios.Hdr =3D (SMBIOS_STRUCTURE *) (UINTN) Smbios30Table->TableAddres= s; SmbiosEnd.Raw =3D (UINT8 *) (UINTN) (Smbios30Table->TableAddress + Smb= ios30Table->TableMaximumSize); @@ -3234,11 +3320,14 @@ NetLibGetSystemGuid ( } while (Smbios.Raw < SmbiosEnd.Raw); return EFI_NOT_FOUND; } =20 /** - Create Dns QName according the queried domain name.=20 + Create Dns QName according the queried domain name. + + If DomainName is NULL, then ASSERT(). + =20 QName is a domain name represented as a sequence of labels,=20 where each label consists of a length octet followed by that=20 number of octets. The QName terminates with the zero=20 length octet for the null label of the root. Caller should=20 take responsibility to free the buffer in returned pointer. @@ -3260,10 +3349,12 @@ NetLibCreateDnsQName ( CHAR8 *Header; CHAR8 *Tail; UINTN Len; UINTN Index; =20 + ASSERT (DomainName !=3D NULL); + QueryName =3D NULL; QueryNameSize =3D 0; Header =3D NULL; Tail =3D NULL; =20 --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 03:36:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1514946736053422.9446331927709; Tue, 2 Jan 2018 18:32:16 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 633A8222A54E0; Tue, 2 Jan 2018 18:27:11 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 599F1222A54D7 for ; Tue, 2 Jan 2018 18:27:09 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jan 2018 18:32:12 -0800 Received: from fanwang2-hp.ccr.corp.intel.com ([10.239.9.33]) by orsmga001.jf.intel.com with ESMTP; 02 Jan 2018 18:32:11 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=fan.wang@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,500,1508828400"; d="scan'208";a="20931429" From: fanwang2 To: edk2-devel@lists.01.org Date: Wed, 3 Jan 2018 10:31:51 +0800 Message-Id: <1514946711-4056-4-git-send-email-fan.wang@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1514946711-4056-1-git-send-email-fan.wang@intel.com> References: <1514946711-4056-1-git-send-email-fan.wang@intel.com> Subject: [edk2] [Patch 3/3] MdeModulePkg/DxeNetLib: Fix an error in packet length counting. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Wang Fan , Fu Siyuan , Jiaxin Wu MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Wang Fan * In old implementation, the operation len-- assumes AsciiSPrint() has counted NULL terminator, and it's not correct. This patch is to fix this issue. Cc: Fu Siyuan Cc: Ye Ting Cc: Jiaxin Wu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wang Fan Reviewed-by: Jiaxin Wu --- MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Libr= ary/DxeNetLib/DxeNetLib.c index 90f17b7..cbce28f 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c @@ -401,22 +401,21 @@ SyslogBuildPacket ( Time.Day, Time.Hour, Time.Minute, Time.Second ); - Len--; =20 Len +=3D (UINT32) AsciiSPrint ( Buf + Len, BufLen - Len, "Tiano %a: %a (Line: %d File: %a)", Module, Message, Line, File ); - Len--; + Len ++; =20 // // OK, patch the IP length/checksum and UDP length fields. // Len +=3D sizeof (EFI_UDP_HEADER); --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel