diff options
author | Zhang Lubo <lubo.zhang@intel.com> | 2015-07-08 06:35:37 +0000 |
---|---|---|
committer | luobozhang <luobozhang@Edk2> | 2015-07-08 06:35:37 +0000 |
commit | 206b5f51beb15a22417c42e846678425de60c556 (patch) | |
tree | 6e33cbdf89c90e6549b77c651b7e10b227357035 /MdeModulePkg/Universal/Network/UefiPxeBcDxe | |
parent | 56b1927aa107e65070879a53562b7bcdc1e918d8 (diff) | |
download | edk2-platforms-206b5f51beb15a22417c42e846678425de60c556.tar.xz |
MdeModulePkg: Replace unsafe string functions.
Replace unsafe string functions with new added safe string functions.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17881 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Universal/Network/UefiPxeBcDxe')
4 files changed, 30 insertions, 23 deletions
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.c index aa73132cb5..8017b73dd7 100644 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.c +++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.c @@ -1,7 +1,7 @@ /** @file
PxeBc MTFTP functions.
-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
@@ -60,7 +60,7 @@ PxeBcCheckPacket ( if (Packet->OpCode == EFI_MTFTP4_OPCODE_ERROR) {
Private->Mode.TftpErrorReceived = TRUE;
Private->Mode.TftpError.ErrorCode = (UINT8) Packet->Error.ErrorCode;
- AsciiStrnCpy (Private->Mode.TftpError.ErrorString, (CHAR8 *) Packet->Error.ErrorMessage, PXE_MTFTP_ERROR_STRING_LENGTH);
+ AsciiStrnCpyS (Private->Mode.TftpError.ErrorString, PXE_MTFTP_ERROR_STRING_LENGTH, (CHAR8 *) Packet->Error.ErrorMessage, PXE_MTFTP_ERROR_STRING_LENGTH - 1);
Private->Mode.TftpError.ErrorString[PXE_MTFTP_ERROR_STRING_LENGTH - 1] = '\0';
}
@@ -135,13 +135,13 @@ PxeBcTftpGetFileSize ( }
ReqOpt[0].OptionStr = (UINT8*)mMtftpOptions[PXE_MTFTP_OPTION_TSIZE_INDEX];
- UtoA10 (0, (CHAR8 *) OptBuf);
+ UtoA10 (0, (CHAR8 *) 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 = ReqOpt[0].ValueStr + AsciiStrLen ((CHAR8 *) ReqOpt[0].ValueStr) + 1;
- UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[1].ValueStr);
+ UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[1].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX - (AsciiStrLen ((CHAR8 *) ReqOpt[0].ValueStr) + 1));
OptCnt++;
}
@@ -160,10 +160,11 @@ PxeBcTftpGetFileSize ( if (Status == EFI_TFTP_ERROR) {
Private->Mode.TftpErrorReceived = TRUE;
Private->Mode.TftpError.ErrorCode = (UINT8) Packet->Error.ErrorCode;
- AsciiStrnCpy (
- Private->Mode.TftpError.ErrorString,
- (CHAR8 *) Packet->Error.ErrorMessage,
- PXE_MTFTP_ERROR_STRING_LENGTH
+ AsciiStrnCpyS (
+ Private->Mode.TftpError.ErrorString,
+ PXE_MTFTP_ERROR_STRING_LENGTH,
+ (CHAR8 *) Packet->Error.ErrorMessage,
+ PXE_MTFTP_ERROR_STRING_LENGTH - 1
);
Private->Mode.TftpError.ErrorString[PXE_MTFTP_ERROR_STRING_LENGTH - 1] = '\0';
}
@@ -261,7 +262,7 @@ PxeBcTftpReadFile ( ReqOpt[0].OptionStr = (UINT8*) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
ReqOpt[0].ValueStr = OptBuf;
- UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr);
+ UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);
OptCnt++;
}
@@ -344,7 +345,7 @@ PxeBcTftpWriteFile ( ReqOpt[0].OptionStr = (UINT8*) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
ReqOpt[0].ValueStr = OptBuf;
- UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr);
+ UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);
OptCnt++;
}
@@ -418,7 +419,7 @@ PxeBcTftpReadDirectory ( ReqOpt[0].OptionStr = (UINT8*) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
ReqOpt[0].ValueStr = OptBuf;
- UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr);
+ UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);
OptCnt++;
}
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.h b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.h index 9920aff8b0..241b079d72 100644 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.h +++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.h @@ -1,7 +1,7 @@ /** @file
Mtftp routines for PxeBc.
-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
@@ -22,6 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #define PXE_MTFTP_OPTION_MAXIMUM_INDEX 4
#define PXE_MTFTP_ERROR_STRING_LENGTH 127
+#define PXE_MTFTP_OPTBUF_MAXNUM_INDEX 128
/**
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c index 327e4a26d8..3016da7324 100644 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c +++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c @@ -1,7 +1,7 @@ /** @file
Support routines for PxeBc.
-Copyright (c) 2007 - 2011, 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
@@ -140,16 +140,18 @@ CvtNum ( /**
Convert unsigned int number to decimal number.
- @param Number The unsigned int number will be converted.
- @param Buffer Pointer to the buffer to store the decimal number after transform.
-
+ @param Number The unsigned int number will be converted.
+ @param Buffer Pointer to the buffer to store the decimal number after transform.
+ @param[in] BufferSize The maxsize of the buffer.
+
@return the length of the number after transform.
**/
UINTN
UtoA10 (
IN UINTN Number,
- IN CHAR8 *Buffer
+ IN CHAR8 *Buffer,
+ IN UINTN BufferSize
)
{
UINTN Index;
@@ -164,7 +166,7 @@ UtoA10 ( Number = Number / 10;
} while (Number != 0);
- AsciiStrCpy (Buffer, &TempStr[Index]);
+ AsciiStrCpyS (Buffer, BufferSize, &TempStr[Index]);
return AsciiStrLen (Buffer);
}
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h index 96f48f56de..6f41aa671d 100644 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h +++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h @@ -1,6 +1,6 @@ /** @file
Support routines for PxeBc.
-Copyright (c) 2007 - 2011, 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
@@ -82,16 +82,19 @@ CvtNum ( /**
Convert unsigned int number to decimal number.
- @param Number The unsigned int number will be converted.
- @param Buffer Pointer to the buffer to store the decimal number after transform.
-
+ @param Number The unsigned int number will be converted.
+ @param Buffer Pointer to the buffer to store the decimal number after transform.
+ @param[in] BufferSize The maxsize of the buffer.
+
@return the length of the number after transform.
**/
UINTN
UtoA10 (
IN UINTN Number,
- IN CHAR8 *Buffer
+ IN CHAR8 *Buffer,
+ IN UINTN BufferSize
+
);
|