X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=NetworkPkg%2FMtftp6Dxe%2FMtftp6Support.c;h=e6b4127b785d82e448ac6a24e854e719324b3192;hb=b575ca32c8b05af5c23f46728ccf4937f2889ba8;hp=24ce0e85badf0a94db747492b7bd86baada9f7e1;hpb=a3bcde70e6dc69000f85cc5deee98101d2ae200a;p=mirror_edk2.git diff --git a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c index 24ce0e85ba..e6b4127b78 100644 --- a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c +++ b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c @@ -1,7 +1,7 @@ /** @file Mtftp6 support functions implementation. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -223,7 +223,7 @@ Mtftp6RemoveBlockNum ( *TotalBlock = Num; if (Range->Round > 0) { - *TotalBlock += Range->Bound + MultU64x32 ((UINT64) (Range->Round -1), (UINT32)(Range->Bound + 1)) + 1; + *TotalBlock += Range->Bound + MultU64x32 (Range->Round - 1, (UINT32)(Range->Bound + 1)) + 1; } if (Range->Start > Range->Bound) { @@ -319,6 +319,29 @@ Mtftp6GetMapping ( Status = Udp6->GetModeData (Udp6, NULL, &Ip6Mode, NULL, NULL); if (!EFI_ERROR (Status)) { + if (Ip6Mode.AddressList != NULL) { + FreePool (Ip6Mode.AddressList); + } + + if (Ip6Mode.GroupTable != NULL) { + FreePool (Ip6Mode.GroupTable); + } + + if (Ip6Mode.RouteTable != NULL) { + FreePool (Ip6Mode.RouteTable); + } + + if (Ip6Mode.NeighborCache != NULL) { + FreePool (Ip6Mode.NeighborCache); + } + + if (Ip6Mode.PrefixTable != NULL) { + FreePool (Ip6Mode.PrefixTable); + } + + if (Ip6Mode.IcmpTypeList != NULL) { + FreePool (Ip6Mode.IcmpTypeList); + } if (Ip6Mode.IsConfigured) { // @@ -452,13 +475,16 @@ Mtftp6SendRequest ( EFI_MTFTP6_PACKET *Packet; EFI_MTFTP6_OPTION *Options; EFI_MTFTP6_TOKEN *Token; + RETURN_STATUS Status; NET_BUF *Nbuf; UINT8 *Mode; UINT8 *Cur; - UINT32 Len1; - UINT32 Len2; - UINT32 Len; UINTN Index; + UINT32 BufferLength; + UINTN FileNameLength; + UINTN ModeLength; + UINTN OptionStrLength; + UINTN ValueStrLength; Token = Instance->Token; Options = Token->OptionList; @@ -487,44 +513,59 @@ Mtftp6SendRequest ( // // Compute the size of new Mtftp6 packet. // - Len1 = (UINT32) AsciiStrLen ((CHAR8 *) Token->Filename); - Len2 = (UINT32) AsciiStrLen ((CHAR8 *) Mode); - Len = Len1 + Len2 + 4; + FileNameLength = AsciiStrLen ((CHAR8 *) Token->Filename); + ModeLength = AsciiStrLen ((CHAR8 *) Mode); + BufferLength = (UINT32) FileNameLength + (UINT32) ModeLength + 4; for (Index = 0; Index < Token->OptionCount; Index++) { - Len1 = (UINT32) AsciiStrLen ((CHAR8 *) Options[Index].OptionStr); - Len2 = (UINT32) AsciiStrLen ((CHAR8 *) Options[Index].ValueStr); - Len += Len1 + Len2 + 2; + OptionStrLength = AsciiStrLen ((CHAR8 *) Options[Index].OptionStr); + ValueStrLength = AsciiStrLen ((CHAR8 *) Options[Index].ValueStr); + BufferLength += (UINT32) OptionStrLength + (UINT32) ValueStrLength + 2; } // // Allocate a packet then copy the data. // - if ((Nbuf = NetbufAlloc (Len)) == NULL) { + if ((Nbuf = NetbufAlloc (BufferLength)) == NULL) { return EFI_OUT_OF_RESOURCES; } // // Copy the opcode, filename and mode into packet. // - Packet = (EFI_MTFTP6_PACKET *) NetbufAllocSpace (Nbuf, Len, FALSE); + Packet = (EFI_MTFTP6_PACKET *) NetbufAllocSpace (Nbuf, BufferLength, FALSE); ASSERT (Packet != NULL); Packet->OpCode = HTONS (Operation); + BufferLength -= sizeof (Packet->OpCode); + Cur = Packet->Rrq.Filename; - Cur = (UINT8 *) AsciiStrCpy ((CHAR8 *) Cur, (CHAR8 *) Token->Filename); - Cur += AsciiStrLen ((CHAR8 *) Token->Filename) + 1; - Cur = (UINT8 *) AsciiStrCpy ((CHAR8 *) Cur, (CHAR8 *) Mode); - Cur += AsciiStrLen ((CHAR8 *) Mode) + 1; + Status = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Token->Filename); + ASSERT_EFI_ERROR (Status); + BufferLength -= (UINT32) (FileNameLength + 1); + Cur += FileNameLength + 1; + Status = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Mode); + ASSERT_EFI_ERROR (Status); + BufferLength -= (UINT32) (ModeLength + 1); + Cur += ModeLength + 1; // // Copy all the extension options into the packet. // for (Index = 0; Index < Token->OptionCount; ++Index) { - Cur = (UINT8 *) AsciiStrCpy ((CHAR8 *) Cur, (CHAR8 *) Options[Index].OptionStr); - Cur += AsciiStrLen ((CHAR8 *) Options[Index].OptionStr) + 1; - Cur = (UINT8 *) AsciiStrCpy ((CHAR8 *) Cur, (CHAR8 *) Options[Index].ValueStr); - Cur += AsciiStrLen ((CHAR8 *) (CHAR8 *) Options[Index].ValueStr) + 1; + OptionStrLength = AsciiStrLen ((CHAR8 *) Options[Index].OptionStr); + ValueStrLength = AsciiStrLen ((CHAR8 *) Options[Index].ValueStr); + + Status = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Options[Index].OptionStr); + ASSERT_EFI_ERROR (Status); + BufferLength -= (UINT32) (OptionStrLength + 1); + Cur += OptionStrLength + 1; + + Status = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Options[Index].ValueStr); + ASSERT_EFI_ERROR (Status); + BufferLength -= (UINT32) (ValueStrLength + 1); + Cur += ValueStrLength + 1; + } // @@ -584,7 +625,7 @@ Mtftp6SendError ( TftpError->OpCode = HTONS (EFI_MTFTP6_OPCODE_ERROR); TftpError->Error.ErrorCode = HTONS (ErrCode); - AsciiStrCpy ((CHAR8 *) TftpError->Error.ErrorMessage, (CHAR8 *) ErrInfo); + AsciiStrCpyS ((CHAR8 *) TftpError->Error.ErrorMessage, AsciiStrLen ((CHAR8 *) ErrInfo) + 1 , (CHAR8 *) ErrInfo); // // Save the packet buf for retransmit @@ -903,6 +944,12 @@ Mtftp6OperationClean ( } if (Instance->McastUdpIo != NULL) { + gBS->CloseProtocol ( + Instance->McastUdpIo->UdpHandle, + &gEfiUdp6ProtocolGuid, + Instance->McastUdpIo->Image, + Instance->Handle + ); UdpIoFreeIo (Instance->McastUdpIo); Instance->McastUdpIo = NULL; }