Discussion:
[edk2] [patch v3] NetworkPkg:Replace unsafe string functions.
Zhang Lubo
2015-07-06 01:09:26 UTC
Permalink
Message-ID: <0be33fc7-8f10-4c82-88e1-***@LUBOZHAN-MOBL.local>
X-Mailer: TortoiseGit
MIME-Version: 1.0
Content-Type: text/plain;

Version v3 including the following updates relative to original one:
Use AllocateCopyPool instead of AllcoateZeroPool to make code easier to understand.
Use macro definition instead of constant number.
Use non-n version of safe string copy function in some cases.
Update Copyright year.

Replace unsafe string functions with new added safe string functions.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <***@intel.com>
Reviewed-by: Fu Siyuan <***@intel.com>
Reviewed-by: Qiu Shumin <***@intel.com>
Reviewed-by: Jaben Carsey <***@intel.com>
---
NetworkPkg/Application/IfConfig6/IfConfig6.c | 13 ++----
NetworkPkg/Application/IpsecConfig/Indexer.c | 4 +-
.../Application/IpsecConfig/PolicyEntryOperation.c | 6 +--
NetworkPkg/IScsiDxe/IScsiConfig.c | 2 +-
NetworkPkg/IScsiDxe/IScsiDhcp.c | 2 +-
NetworkPkg/IScsiDxe/IScsiDhcp6.c | 4 +-
NetworkPkg/IScsiDxe/IScsiExtScsiPassThru.c | 4 +-
NetworkPkg/Mtftp6Dxe/Mtftp6Support.c | 15 ++++---
NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.c | 46 +++++++++++-----------
NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.h | 3 +-
NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c | 8 ++--
NetworkPkg/UefiPxeBcDxe/PxeBcSupport.h | 6 ++-
12 files changed, 58 insertions(+), 55 deletions(-)

diff --git a/NetworkPkg/Application/IfConfig6/IfConfig6.c b/NetworkPkg/Application/IfConfig6/IfConfig6.c
index 9e228ca..e66d52a 100644
--- a/NetworkPkg/Application/IfConfig6/IfConfig6.c
+++ b/NetworkPkg/Application/IfConfig6/IfConfig6.c
@@ -1,9 +1,9 @@
/** @file
The implementation for Shell application IfConfig6.

- Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>

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.
@@ -132,13 +132,12 @@ SplitStrToList (
}

//
// Copy the CONST string to a local copy.
//
- Str = (CHAR16 *) AllocateZeroPool (StrSize (String));
+ Str = AllocateCopyPool (StrSize (String), String);
ASSERT (Str != NULL);
- Str = StrnCpy (Str, String, StrLen (String));
ArgStr = Str;

//
// init a node for the list head.
//
@@ -1715,28 +1714,24 @@ IfConfig6Initialize (
//
if (ShellCommandLineGetFlag (ParamPackage, L"-l")) {
Private->OpCode = IfConfig6OpList;
ValueStr = ShellCommandLineGetValue (ParamPackage, L"-l");
if (ValueStr != NULL) {
- Str = (CHAR16 *) AllocateZeroPool (StrSize (ValueStr));
+ Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);
ASSERT (Str != NULL);
-
- Str = StrnCpy (Str, ValueStr, StrLen (ValueStr));
Private->IfName = Str;
}
}
//
// To get interface name for the clear option.
//
if (ShellCommandLineGetFlag (ParamPackage, L"-r")) {
Private->OpCode = IfConfig6OpClear;
ValueStr = ShellCommandLineGetValue (ParamPackage, L"-r");
if (ValueStr != NULL) {
- Str = (CHAR16 *) AllocateZeroPool (StrSize (ValueStr));
+ Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);
ASSERT (Str != NULL);
-
- Str = StrnCpy (Str, ValueStr, StrLen (ValueStr));
Private->IfName = Str;
}
}
//
// To get interface name and corresponding Args for the set option.
diff --git a/NetworkPkg/Application/IpsecConfig/Indexer.c b/NetworkPkg/Application/IpsecConfig/Indexer.c
index 9e066b1..bb27afb 100644
--- a/NetworkPkg/Application/IpsecConfig/Indexer.c
+++ b/NetworkPkg/Application/IpsecConfig/Indexer.c
@@ -1,9 +1,9 @@
/** @file
The implementation of construct ENTRY_INDEXER in IpSecConfig application.

- Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>

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.
@@ -233,11 +233,11 @@ ConstructPadIndexer (
return EFI_INVALID_PARAMETER;
}

Indexer->PadId.PeerIdValid = TRUE;
ZeroMem (Indexer->PadId.Id.PeerId, MAX_PEERID_LEN);
- StrnCpy ((CHAR16 *) Indexer->PadId.Id.PeerId, ValueStr, ARRAY_SIZE (Indexer->PadId.Id.PeerId) - 1);
+ StrCpyS ((CHAR16 *) Indexer->PadId.Id.PeerId, MAX_PEERID_LEN / sizeof (CHAR16), ValueStr);
}
}

return EFI_SUCCESS;
}
diff --git a/NetworkPkg/Application/IpsecConfig/PolicyEntryOperation.c b/NetworkPkg/Application/IpsecConfig/PolicyEntryOperation.c
index 7e04573..380bad6 100644
--- a/NetworkPkg/Application/IpsecConfig/PolicyEntryOperation.c
+++ b/NetworkPkg/Application/IpsecConfig/PolicyEntryOperation.c
@@ -1,9 +1,9 @@
/** @file
The implementation of policy entry operation function in IpSecConfig application.

- Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>

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.
@@ -1102,11 +1102,11 @@ CreatePadEntry (
}

ValueStr = ShellCommandLineGetValue (ParamPackage, L"--peer-id");
if (ValueStr != NULL) {
(*PadId)->PeerIdValid = TRUE;
- StrnCpy ((CHAR16 *) (*PadId)->Id.PeerId, ValueStr, ARRAY_SIZE ((*PadId)->Id.PeerId) - 1);
+ StrCpyS ((CHAR16 *) (*PadId)->Id.PeerId, MAX_PEERID_LEN / sizeof (CHAR16), ValueStr);
*Mask |= PEER_ID;
}

ValueStr = ShellCommandLineGetValue (ParamPackage, L"--auth-data");
if (ValueStr != NULL) {
@@ -1397,11 +1397,11 @@ CombineSpdEntry (
}
//
// Process Data
//
if ((Mask & NAME) != 0) {
- AsciiStrCpy ((CHAR8 *) OldData->Name, (CHAR8 *) NewData->Name);
+ AsciiStrCpyS ((CHAR8 *) OldData->Name, MAX_PEERID_LEN, (CHAR8 *) NewData->Name);
}

if ((Mask & PACKET_FLAG) != 0) {
OldData->PackageFlag = NewData->PackageFlag;
}
diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.c b/NetworkPkg/IScsiDxe/IScsiConfig.c
index 5cb1157..9b644a3 100644
--- a/NetworkPkg/IScsiDxe/IScsiConfig.c
+++ b/NetworkPkg/IScsiDxe/IScsiConfig.c
@@ -2391,11 +2391,11 @@ IScsiFormCallback (
&Key,
L"Invalid iSCSI Name!",
NULL
);
} else {
- AsciiStrCpy (Private->Current->SessionConfigData.TargetName, IScsiName);
+ AsciiStrCpyS (Private->Current->SessionConfigData.TargetName, ISCSI_NAME_MAX_SIZE,IScsiName);
}

break;

case KEY_DHCP_ENABLE:
diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp.c b/NetworkPkg/IScsiDxe/IScsiDhcp.c
index 3706256..fa2412e 100644
--- a/NetworkPkg/IScsiDxe/IScsiDhcp.c
+++ b/NetworkPkg/IScsiDxe/IScsiDhcp.c
@@ -173,11 +173,11 @@ IScsiDhcpExtractRootPath (
Status = IScsiNormalizeName (Field->Str, AsciiStrLen (Field->Str));
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}

- AsciiStrCpy (ConfigNvData->TargetName, Field->Str);
+ AsciiStrCpyS (ConfigNvData->TargetName, ISCSI_NAME_MAX_SIZE, Field->Str);

ON_EXIT:

FreePool (TmpStr);

diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp6.c b/NetworkPkg/IScsiDxe/IScsiDhcp6.c
index 2627a59..331b0f1 100644
--- a/NetworkPkg/IScsiDxe/IScsiDhcp6.c
+++ b/NetworkPkg/IScsiDxe/IScsiDhcp6.c
@@ -1,9 +1,9 @@
/** @file
iSCSI DHCP6 related configuration routines.

-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
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

@@ -201,11 +201,11 @@ IScsiDhcp6ExtractRootPath (
Status = IScsiNormalizeName (Field->Str, AsciiStrLen (Field->Str));
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}

- AsciiStrCpy (ConfigNvData->TargetName, Field->Str);
+ AsciiStrCpyS (ConfigNvData->TargetName, ISCSI_NAME_MAX_SIZE, Field->Str);

ON_EXIT:

FreePool (TmpStr);

diff --git a/NetworkPkg/IScsiDxe/IScsiExtScsiPassThru.c b/NetworkPkg/IScsiDxe/IScsiExtScsiPassThru.c
index c785853..f971244 100644
--- a/NetworkPkg/IScsiDxe/IScsiExtScsiPassThru.c
+++ b/NetworkPkg/IScsiDxe/IScsiExtScsiPassThru.c
@@ -1,9 +1,9 @@
/** @file
The implementation of EFI_EXT_SCSI_PASS_THRU_PROTOCOL.

-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
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

@@ -271,11 +271,11 @@ IScsiExtScsiPassThruBuildDevicePath (
break;
}

CopyMem (&Node->Iscsi.Lun, ConfigNvData->BootLun, sizeof (UINT64));
Node->Iscsi.TargetPortalGroupTag = Session->TargetPortalGroupTag;
- AsciiStrCpy ((CHAR8 *) Node + sizeof (ISCSI_DEVICE_PATH), ConfigNvData->TargetName);
+ AsciiStrCpyS ((CHAR8 *) Node + sizeof (ISCSI_DEVICE_PATH), AsciiStrLen (ConfigNvData->TargetName) + 1, ConfigNvData->TargetName);

*DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node;

return EFI_SUCCESS;
}
diff --git a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
index f5b2231..04c09df 100644
--- a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
+++ b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
@@ -1,9 +1,9 @@
/** @file
Mtftp6 support functions implementation.

- Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>

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.
@@ -510,23 +510,26 @@ Mtftp6SendRequest (
Packet = (EFI_MTFTP6_PACKET *) NetbufAllocSpace (Nbuf, Len, FALSE);
ASSERT (Packet != NULL);

Packet->OpCode = HTONS (Operation);
Cur = Packet->Rrq.Filename;
- Cur = (UINT8 *) AsciiStrCpy ((CHAR8 *) Cur, (CHAR8 *) Token->Filename);
+ Cur = (UINT8 *) AsciiStrCpyS ((CHAR8 *) Cur, Len - 2, (CHAR8 *) Token->Filename);
Cur += AsciiStrLen ((CHAR8 *) Token->Filename) + 1;
- Cur = (UINT8 *) AsciiStrCpy ((CHAR8 *) Cur, (CHAR8 *) Mode);
+ Cur = (UINT8 *) AsciiStrCpyS ((CHAR8 *) Cur, Len - 2 - (AsciiStrLen ((CHAR8 *) Token->Filename) + 1), (CHAR8 *) Mode);
Cur += AsciiStrLen ((CHAR8 *) Mode) + 1;
+ Len -= ((UINT32) AsciiStrLen ((CHAR8 *) Token->Filename) + (UINT32) AsciiStrLen ((CHAR8 *) Mode) + 4);

//
// 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 = (UINT8 *) AsciiStrCpyS ((CHAR8 *) Cur, Len, (CHAR8 *) Options[Index].OptionStr);
Cur += AsciiStrLen ((CHAR8 *) Options[Index].OptionStr) + 1;
- Cur = (UINT8 *) AsciiStrCpy ((CHAR8 *) Cur, (CHAR8 *) Options[Index].ValueStr);
+ Len -= (AsciiStrLen ((CHAR8 *) Options[Index].OptionStr) + 1);
+ Cur = (UINT8 *) AsciiStrCpyS ((CHAR8 *) Cur, Len, (CHAR8 *) Options[Index].ValueStr);
Cur += AsciiStrLen ((CHAR8 *) (CHAR8 *) Options[Index].ValueStr) + 1;
+ Len -= (AsciiStrLen ((CHAR8 *) (CHAR8 *) Options[Index].ValueStr) + 1);
}

//
// Save the packet buf for retransmit
//
@@ -582,11 +585,11 @@ 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, ARRAY_SIZE (TftpError->Error.ErrorMessage), (CHAR8 *) ErrInfo);

//
// Save the packet buf for retransmit
//
if (Instance->LastPacket != NULL) {
diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.c b/NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.c
index 09196c7..98bb496 100644
--- a/NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.c
+++ b/NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.c
@@ -1,9 +1,9 @@
/** @file
Functions implementation related with Mtftp for UefiPxeBc Driver.

- Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>

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.
@@ -62,14 +62,14 @@ PxeBcMtftp6CheckPacket (
//
// Store the tftp error message into mode data and set the received flag.
//
Private->Mode.TftpErrorReceived = TRUE;
Private->Mode.TftpError.ErrorCode = (UINT8) Packet->Error.ErrorCode;
- AsciiStrnCpy (
+ AsciiStrCpyS (
Private->Mode.TftpError.ErrorString,
- (CHAR8 *) Packet->Error.ErrorMessage,
- PXE_MTFTP_ERROR_STRING_LENGTH
+ PXE_MTFTP_ERROR_STRING_LENGTH,
+ (CHAR8 *) Packet->Error.ErrorMessage
);
Private->Mode.TftpError.ErrorString[PXE_MTFTP_ERROR_STRING_LENGTH - 1] = '\0';
}

if (Callback != NULL) {
@@ -149,17 +149,17 @@ PxeBcMtftp6GetFileSize (

//
// Build the required options for get info.
//
ReqOpt[0].OptionStr = (UINT8 *) mMtftpOptions[PXE_MTFTP_OPTION_TSIZE_INDEX];
- PxeBcUintnToAscDec (0, OptBuf);
+ PxeBcUintnToAscDec (0, OptBuf, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);
ReqOpt[0].ValueStr = OptBuf;

if (BlockSize != NULL) {
ReqOpt[1].OptionStr = (UINT8 *) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
ReqOpt[1].ValueStr = (UINT8 *) (ReqOpt[0].ValueStr + AsciiStrLen ((CHAR8 *) ReqOpt[0].ValueStr) + 1);
- PxeBcUintnToAscDec (*BlockSize, ReqOpt[1].ValueStr);
+ PxeBcUintnToAscDec (*BlockSize, ReqOpt[1].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX - (AsciiStrLen ((CHAR8 *) ReqOpt[0].ValueStr) + 1));
OptCnt++;
}

Status = Mtftp6->GetInfo (
Mtftp6,
@@ -176,14 +176,14 @@ PxeBcMtftp6GetFileSize (
//
// Store the tftp error message into mode data and set the received flag.
//
Private->Mode.TftpErrorReceived = TRUE;
Private->Mode.TftpError.ErrorCode = (UINT8) Packet->Error.ErrorCode;
- AsciiStrnCpy (
+ AsciiStrCpyS (
Private->Mode.TftpError.ErrorString,
- (CHAR8 *) Packet->Error.ErrorMessage,
- PXE_MTFTP_ERROR_STRING_LENGTH
+ PXE_MTFTP_ERROR_STRING_LENGTH,
+ (CHAR8 *) Packet->Error.ErrorMessage
);
Private->Mode.TftpError.ErrorString[PXE_MTFTP_ERROR_STRING_LENGTH - 1] = '\0';
}
goto ON_ERROR;
}
@@ -271,11 +271,11 @@ PxeBcMtftp6ReadFile (
}

if (BlockSize != NULL) {
ReqOpt[0].OptionStr = (UINT8 *) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
ReqOpt[0].ValueStr = OptBuf;
- PxeBcUintnToAscDec (*BlockSize, ReqOpt[0].ValueStr);
+ PxeBcUintnToAscDec (*BlockSize, ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);
OptCnt++;
}

Token.Event = NULL;
Token.OverrideData = NULL;
@@ -354,11 +354,11 @@ PxeBcMtftp6WriteFile (
}

if (BlockSize != NULL) {
ReqOpt[0].OptionStr = (UINT8 *) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
ReqOpt[0].ValueStr = OptBuf;
- PxeBcUintnToAscDec (*BlockSize, ReqOpt[0].ValueStr);
+ PxeBcUintnToAscDec (*BlockSize, ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);
OptCnt++;
}

Token.Event = NULL;
Token.OverrideData = NULL;
@@ -429,11 +429,11 @@ PxeBcMtftp6ReadDirectory (
}

if (BlockSize != NULL) {
ReqOpt[0].OptionStr = (UINT8 *) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
ReqOpt[0].ValueStr = OptBuf;
- PxeBcUintnToAscDec (*BlockSize, ReqOpt[0].ValueStr);
+ PxeBcUintnToAscDec (*BlockSize, ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);
OptCnt++;
}

Token.Event = NULL;
Token.OverrideData = NULL;
@@ -506,14 +506,14 @@ PxeBcMtftp4CheckPacket (
//
// Store the tftp error message into mode data and set the received flag.
//
Private->Mode.TftpErrorReceived = TRUE;
Private->Mode.TftpError.ErrorCode = (UINT8) Packet->Error.ErrorCode;
- AsciiStrnCpy (
+ AsciiStrCpyS (
Private->Mode.TftpError.ErrorString,
- (CHAR8 *) Packet->Error.ErrorMessage,
- PXE_MTFTP_ERROR_STRING_LENGTH
+ PXE_MTFTP_ERROR_STRING_LENGTH,
+ (CHAR8 *) Packet->Error.ErrorMessage
);
Private->Mode.TftpError.ErrorString[PXE_MTFTP_ERROR_STRING_LENGTH - 1] = '\0';
}

if (Callback != NULL) {
@@ -593,17 +593,17 @@ PxeBcMtftp4GetFileSize (

//
// Build the required options for get info.
//
ReqOpt[0].OptionStr = (UINT8 *) mMtftpOptions[PXE_MTFTP_OPTION_TSIZE_INDEX];
- PxeBcUintnToAscDec (0, OptBuf);
+ PxeBcUintnToAscDec (0, OptBuf, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);
ReqOpt[0].ValueStr = OptBuf;

if (BlockSize != NULL) {
ReqOpt[1].OptionStr = (UINT8 *) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
ReqOpt[1].ValueStr = (UINT8 *) (ReqOpt[0].ValueStr + AsciiStrLen ((CHAR8 *) ReqOpt[0].ValueStr) + 1);
- PxeBcUintnToAscDec (*BlockSize, ReqOpt[1].ValueStr);
+ PxeBcUintnToAscDec (*BlockSize, ReqOpt[1].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX - (AsciiStrLen ((CHAR8 *) ReqOpt[0].ValueStr) + 1));
OptCnt++;
}

Status = Mtftp4->GetInfo (
Mtftp4,
@@ -620,14 +620,14 @@ PxeBcMtftp4GetFileSize (
//
// Store the tftp error message into mode data and set the received flag.
//
Private->Mode.TftpErrorReceived = TRUE;
Private->Mode.TftpError.ErrorCode = (UINT8) Packet->Error.ErrorCode;
- AsciiStrnCpy (
+ AsciiStrCpyS (
Private->Mode.TftpError.ErrorString,
- (CHAR8 *) Packet->Error.ErrorMessage,
- PXE_MTFTP_ERROR_STRING_LENGTH
+ PXE_MTFTP_ERROR_STRING_LENGTH,
+ (CHAR8 *) Packet->Error.ErrorMessage
);
Private->Mode.TftpError.ErrorString[PXE_MTFTP_ERROR_STRING_LENGTH - 1] = '\0';
}
goto ON_ERROR;
}
@@ -715,11 +715,11 @@ PxeBcMtftp4ReadFile (
}

if (BlockSize != NULL) {
ReqOpt[0].OptionStr = (UINT8 *) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
ReqOpt[0].ValueStr = OptBuf;
- PxeBcUintnToAscDec (*BlockSize, ReqOpt[0].ValueStr);
+ PxeBcUintnToAscDec (*BlockSize, ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);
OptCnt++;
}

Token.Event = NULL;
Token.OverrideData = NULL;
@@ -798,11 +798,11 @@ PxeBcMtftp4WriteFile (
}

if (BlockSize != NULL) {
ReqOpt[0].OptionStr = (UINT8 *) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
ReqOpt[0].ValueStr = OptBuf;
- PxeBcUintnToAscDec (*BlockSize, ReqOpt[0].ValueStr);
+ PxeBcUintnToAscDec (*BlockSize, ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);
OptCnt++;
}

Token.Event = NULL;
Token.OverrideData = NULL;
@@ -873,11 +873,11 @@ PxeBcMtftp4ReadDirectory (
}

if (BlockSize != NULL) {
ReqOpt[0].OptionStr = (UINT8 *) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
ReqOpt[0].ValueStr = OptBuf;
- PxeBcUintnToAscDec (*BlockSize, ReqOpt[0].ValueStr);
+ PxeBcUintnToAscDec (*BlockSize, ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);
OptCnt++;
}

Token.Event = NULL;
Token.OverrideData = NULL;
diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.h b/NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.h
index 1064195..f115076 100644
--- a/NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.h
+++ b/NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.h
@@ -1,9 +1,9 @@
/** @file
Functions declaration related with Mtftp for UefiPxeBc Driver.

- Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>

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.
@@ -19,10 +19,11 @@
#define PXE_MTFTP_OPTION_BLKSIZE_INDEX 0
#define PXE_MTFTP_OPTION_TIMEOUT_INDEX 1
#define PXE_MTFTP_OPTION_TSIZE_INDEX 2
#define PXE_MTFTP_OPTION_MULTICAST_INDEX 3
#define PXE_MTFTP_OPTION_MAXIMUM_INDEX 4
+#define PXE_MTFTP_OPTBUF_MAXNUM_INDEX 128

#define PXE_MTFTP_ERROR_STRING_LENGTH 127 // refer to definition of struct EFI_PXE_BASE_CODE_TFTP_ERROR.
#define PXE_MTFTP_DEFAULT_BLOCK_SIZE 512 // refer to rfc-1350.


diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c b/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c
index 88ae7b6..36b0665 100644
--- a/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c
+++ b/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c
@@ -1,9 +1,9 @@
/** @file
Support functions implementation for UefiPxeBc Driver.

- Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>

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.
@@ -1390,18 +1390,20 @@ PxeBcUintnToAscDecWithFormat (
This function is to convert a UINTN to a ASCII string, and return the
actual length of the buffer.

@param[in] Number Numeric value to be converted.
@param[in] Buffer The pointer to the buffer for ASCII string.
+ @param[in] BufferSize The maxsize of the buffer.

@return Length The actual length of the ASCII string.

**/
UINTN
PxeBcUintnToAscDec (
IN UINTN Number,
- IN UINT8 *Buffer
+ IN UINT8 *Buffer,
+ IN UINTN BufferSize
)
{
UINTN Index;
UINTN Length;
CHAR8 TempStr[64];
@@ -1413,11 +1415,11 @@ PxeBcUintnToAscDec (
Index--;
TempStr[Index] = (CHAR8) ('0' + (Number % 10));
Number = (UINTN) (Number / 10);
} while (Number != 0);

- AsciiStrCpy ((CHAR8 *) Buffer, &TempStr[Index]);
+ AsciiStrCpyS ((CHAR8 *) Buffer, BufferSize, &TempStr[Index]);

Length = AsciiStrLen ((CHAR8 *) Buffer);

return Length;
}
diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.h b/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.h
index fc99fad..0a43aeb 100644
--- a/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.h
+++ b/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.h
@@ -446,18 +446,20 @@ PxeBcUintnToAscDecWithFormat (
This function is to convert a UINTN to a ASCII string, and return the
actual length of the buffer.

@param[in] Number Numeric value to be converted.
@param[in] Buffer Pointer to the buffer for ASCII string.
-
+ @param[in] BufferSize The maxsize of the buffer.
+
@return Length The actual length of the ASCII string.

**/
UINTN
PxeBcUintnToAscDec (
IN UINTN Number,
- IN UINT8 *Buffer
+ IN UINT8 *Buffer,
+ IN UINTN BufferSize
);

/**
This function is to convert unicode hex number to a UINT8.
--
1.9.5.msysgit.1
Loading...