From b523178555ad499ccd223b88258ec48f899edbad Mon Sep 17 00:00:00 2001 From: Dandan Bi Date: Thu, 17 Sep 2015 07:37:44 +0000 Subject: MdeModulePkg:Fix the bug the incorrect change of StrCpyS function The pointer to the destination string changed,the max length also changed.Previous change neglect this point. And base on the code logic,we can use StrCatS to replace StrCpyS.Now this patch is to fix this bug. (Sync patch r18497 from main trunk.) Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Dandan Bi Reviewed-by: Eric Dong git-svn-id: https://svn.code.sf.net/p/edk2/code/branches/UDK2015@18498 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 4 +- .../HiiDatabaseDxe/ConfigKeywordHandler.c | 65 +++++++--------------- 2 files changed, 23 insertions(+), 46 deletions(-) (limited to 'MdeModulePkg') diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index bee5e0d22c..66d72acf27 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -662,7 +662,7 @@ HiiConstructConfigHdr ( // // Append L"&NAME=" // - StrCpyS (String, MaxLen, L"&NAME="); + StrCatS (ReturnString, MaxLen, L"&NAME="); String += StrLen (String); if (Name != NULL) { @@ -677,7 +677,7 @@ HiiConstructConfigHdr ( // // Append L"&PATH=" // - StrCpyS (String, MaxLen, L"&PATH="); + StrCatS (ReturnString, MaxLen, L"&PATH="); String += StrLen (String); // diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c index 6923d6c473..52aa4d8bcf 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c @@ -1758,7 +1758,7 @@ ConstructConfigHdr ( // // Append L"&NAME=" // - StrCpyS (String, MaxLen, L"&NAME="); + StrCatS (ReturnString, MaxLen, L"&NAME="); String += StrLen (String); if (Name != NULL) { @@ -1773,7 +1773,7 @@ ConstructConfigHdr ( // // Append L"&PATH=" // - StrCpyS (String, MaxLen, L"&PATH="); + StrCatS (ReturnString, MaxLen, L"&PATH="); String += StrLen (String); // @@ -2044,14 +2044,10 @@ ExtractConfigRequest ( StringPtr = *ConfigRequest; StrCpyS (StringPtr, MaxLen, ConfigHdr); - StringPtr += StrLen (StringPtr); - *StringPtr = L'&'; - StringPtr++; + StrCatS (StringPtr, MaxLen, L"&"); - StrCpyS (StringPtr, MaxLen, RequestElement); - StringPtr += StrLen (StringPtr); - *StringPtr = L'\0'; + StrCatS (StringPtr, MaxLen, RequestElement); FreePool (ConfigHdr); FreePool (RequestElement); @@ -2152,23 +2148,17 @@ ExtractConfigResp ( StringPtr = *ConfigResp; StrCpyS (StringPtr, MaxLen, ConfigHdr); - StringPtr += StrLen (StringPtr); - *StringPtr = L'&'; - StringPtr++; + StrCatS (StringPtr, MaxLen, L"&"); - StrCpyS (StringPtr, MaxLen, RequestElement); - StringPtr += StrLen (StringPtr); - - *StringPtr = L'&'; - StringPtr++; - StrCpyS (StringPtr, MaxLen, L"VALUE="); - StringPtr += StrLen (StringPtr); + StrCatS (StringPtr, MaxLen, RequestElement); + + StrCatS (StringPtr, MaxLen, L"&"); + + StrCatS (StringPtr, MaxLen, L"VALUE="); - StrCpyS (StringPtr, MaxLen, ValueElement); - StringPtr += StrLen (StringPtr); - *StringPtr = L'\0'; + StrCatS (StringPtr, MaxLen, ValueElement); FreePool (ConfigHdr); FreePool (RequestElement); @@ -2452,43 +2442,33 @@ GenerateKeywordResp ( // 2.1 Copy NameSpaceId section. // StrCpyS (RespStr, RespStrLen, L"NAMESPACE="); - RespStr += StrLen (RespStr); - StrCpyS (RespStr, RespStrLen, UnicodeNameSpace); - RespStr += StrLen (RespStr); + + StrCatS (RespStr, RespStrLen, UnicodeNameSpace); // // 2.2 Copy PathHdr section. // - StrCpyS (RespStr, RespStrLen, PathHdr); - RespStr += StrLen (RespStr); + StrCatS (RespStr, RespStrLen, PathHdr); // // 2.3 Copy Keyword section. // - StrCpyS (RespStr, RespStrLen, L"KEYWORD="); - RespStr += StrLen (RespStr); - StrCpyS (RespStr, RespStrLen, KeywordData); - RespStr += StrLen (RespStr); + StrCatS (RespStr, RespStrLen, L"KEYWORD="); + + StrCatS (RespStr, RespStrLen, KeywordData); // // 2.4 Copy the Value section. // - StrCpyS (RespStr, RespStrLen, ValueStr); - RespStr += StrLen (RespStr); + StrCatS (RespStr, RespStrLen, ValueStr); // // 2.5 Copy ReadOnly section if exist. // if (ReadOnly) { - StrCpyS (RespStr, RespStrLen, L"&READONLY"); - RespStr += StrLen (RespStr); + StrCatS (RespStr, RespStrLen, L"&READONLY"); } - // - // 2.6 Add the end. - // - *RespStr = L'\0'; - if (UnicodeNameSpace != NULL) { FreePool (UnicodeNameSpace); } @@ -2536,12 +2516,9 @@ MergeToMultiKeywordResp ( FreePool (*MultiKeywordResp); *MultiKeywordResp = StringPtr; - StringPtr += StrLen (StringPtr); - - *StringPtr = L'&'; - StringPtr++; + StrCatS (StringPtr, MultiKeywordRespLen / sizeof (CHAR16), L"&"); - StrCpyS (StringPtr, MultiKeywordRespLen / sizeof (CHAR16), *KeywordResp); + StrCatS (StringPtr, MultiKeywordRespLen / sizeof (CHAR16), *KeywordResp); return EFI_SUCCESS; } -- cgit v1.2.3