/** @file\r
Mtftp6 support functions implementation.\r
\r
- Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
Status = Udp6->GetModeData (Udp6, NULL, &Ip6Mode, NULL, NULL);\r
\r
if (!EFI_ERROR (Status)) {\r
+ if (Ip6Mode.AddressList != NULL) {\r
+ FreePool (Ip6Mode.AddressList);\r
+ }\r
+\r
+ if (Ip6Mode.GroupTable != NULL) {\r
+ FreePool (Ip6Mode.GroupTable);\r
+ }\r
+\r
+ if (Ip6Mode.RouteTable != NULL) {\r
+ FreePool (Ip6Mode.RouteTable);\r
+ }\r
+\r
+ if (Ip6Mode.NeighborCache != NULL) {\r
+ FreePool (Ip6Mode.NeighborCache);\r
+ }\r
+\r
+ if (Ip6Mode.PrefixTable != NULL) {\r
+ FreePool (Ip6Mode.PrefixTable);\r
+ }\r
+\r
+ if (Ip6Mode.IcmpTypeList != NULL) {\r
+ FreePool (Ip6Mode.IcmpTypeList);\r
+ }\r
\r
if (Ip6Mode.IsConfigured) {\r
//\r
EFI_MTFTP6_PACKET *Packet;\r
EFI_MTFTP6_OPTION *Options;\r
EFI_MTFTP6_TOKEN *Token;\r
+ RETURN_STATUS Status;\r
NET_BUF *Nbuf;\r
UINT8 *Mode;\r
UINT8 *Cur;\r
- UINT32 Len1;\r
- UINT32 Len2;\r
- UINT32 Len;\r
UINTN Index;\r
+ UINT32 BufferLength;\r
+ UINTN FileNameLength;\r
+ UINTN ModeLength;\r
+ UINTN OptionStrLength;\r
+ UINTN ValueStrLength;\r
\r
Token = Instance->Token;\r
Options = Token->OptionList;\r
//\r
// Compute the size of new Mtftp6 packet.\r
//\r
- Len1 = (UINT32) AsciiStrLen ((CHAR8 *) Token->Filename);\r
- Len2 = (UINT32) AsciiStrLen ((CHAR8 *) Mode);\r
- Len = Len1 + Len2 + 4;\r
+ FileNameLength = AsciiStrLen ((CHAR8 *) Token->Filename);\r
+ ModeLength = AsciiStrLen ((CHAR8 *) Mode);\r
+ BufferLength = (UINT32) FileNameLength + (UINT32) ModeLength + 4;\r
\r
for (Index = 0; Index < Token->OptionCount; Index++) {\r
- Len1 = (UINT32) AsciiStrLen ((CHAR8 *) Options[Index].OptionStr);\r
- Len2 = (UINT32) AsciiStrLen ((CHAR8 *) Options[Index].ValueStr);\r
- Len += Len1 + Len2 + 2;\r
+ OptionStrLength = AsciiStrLen ((CHAR8 *) Options[Index].OptionStr);\r
+ ValueStrLength = AsciiStrLen ((CHAR8 *) Options[Index].ValueStr);\r
+ BufferLength += (UINT32) OptionStrLength + (UINT32) ValueStrLength + 2;\r
}\r
\r
//\r
// Allocate a packet then copy the data.\r
//\r
- if ((Nbuf = NetbufAlloc (Len)) == NULL) {\r
+ if ((Nbuf = NetbufAlloc (BufferLength)) == NULL) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
//\r
// Copy the opcode, filename and mode into packet.\r
//\r
- Packet = (EFI_MTFTP6_PACKET *) NetbufAllocSpace (Nbuf, Len, FALSE);\r
+ Packet = (EFI_MTFTP6_PACKET *) NetbufAllocSpace (Nbuf, BufferLength, FALSE);\r
ASSERT (Packet != NULL);\r
\r
Packet->OpCode = HTONS (Operation);\r
+ BufferLength -= sizeof (Packet->OpCode);\r
+ \r
Cur = Packet->Rrq.Filename;\r
- Cur = (UINT8 *) AsciiStrCpy ((CHAR8 *) Cur, (CHAR8 *) Token->Filename);\r
- Cur += AsciiStrLen ((CHAR8 *) Token->Filename) + 1;\r
- Cur = (UINT8 *) AsciiStrCpy ((CHAR8 *) Cur, (CHAR8 *) Mode);\r
- Cur += AsciiStrLen ((CHAR8 *) Mode) + 1;\r
+ Status = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Token->Filename);\r
+ ASSERT_EFI_ERROR (Status);\r
+ BufferLength -= (UINT32) (FileNameLength + 1);\r
+ Cur += FileNameLength + 1;\r
+ Status = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Mode);\r
+ ASSERT_EFI_ERROR (Status);\r
+ BufferLength -= (UINT32) (ModeLength + 1);\r
+ Cur += ModeLength + 1;\r
\r
//\r
// Copy all the extension options into the packet.\r
//\r
for (Index = 0; Index < Token->OptionCount; ++Index) {\r
- Cur = (UINT8 *) AsciiStrCpy ((CHAR8 *) Cur, (CHAR8 *) Options[Index].OptionStr);\r
- Cur += AsciiStrLen ((CHAR8 *) Options[Index].OptionStr) + 1;\r
- Cur = (UINT8 *) AsciiStrCpy ((CHAR8 *) Cur, (CHAR8 *) Options[Index].ValueStr);\r
- Cur += AsciiStrLen ((CHAR8 *) (CHAR8 *) Options[Index].ValueStr) + 1;\r
+ OptionStrLength = AsciiStrLen ((CHAR8 *) Options[Index].OptionStr);\r
+ ValueStrLength = AsciiStrLen ((CHAR8 *) Options[Index].ValueStr);\r
+ \r
+ Status = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Options[Index].OptionStr);\r
+ ASSERT_EFI_ERROR (Status);\r
+ BufferLength -= (UINT32) (OptionStrLength + 1);\r
+ Cur += OptionStrLength + 1;\r
+ \r
+ Status = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Options[Index].ValueStr);\r
+ ASSERT_EFI_ERROR (Status);\r
+ BufferLength -= (UINT32) (ValueStrLength + 1);\r
+ Cur += ValueStrLength + 1;\r
+ \r
}\r
\r
//\r
TftpError->OpCode = HTONS (EFI_MTFTP6_OPCODE_ERROR);\r
TftpError->Error.ErrorCode = HTONS (ErrCode);\r
\r
- AsciiStrCpy ((CHAR8 *) TftpError->Error.ErrorMessage, (CHAR8 *) ErrInfo);\r
+ AsciiStrCpyS ((CHAR8 *) TftpError->Error.ErrorMessage, AsciiStrLen ((CHAR8 *) ErrInfo) + 1 , (CHAR8 *) ErrInfo);\r
\r
//\r
// Save the packet buf for retransmit\r