Reviewed-by: Rebecca Cran <rebe...@nuviainc.com>


--

Rebecca Cran


On 9/1/21 1:18 AM, Michael D Kinney wrote:
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3361

DestMax must be > Length or StrnCpyS() and AsciiStrnCpyS()
return an error.  Set DestMax to n + 1 for these LibC APIs.

Cc: Rebecca Cran <rebe...@nuviainc.com>
Cc: Jayaprakash Nevara <n.jayaprak...@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kin...@intel.com>
---
  StdLib/LibC/String/Copying.c | 2 +-
  StdLib/LibC/Wchar/Copying.c  | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/StdLib/LibC/String/Copying.c b/StdLib/LibC/String/Copying.c
index c296714..a50331b 100644
--- a/StdLib/LibC/String/Copying.c
+++ b/StdLib/LibC/String/Copying.c
@@ -90,7 +90,7 @@ strcpy(char * __restrict s1, const char * __restrict s2)
  **/
  char     *strncpy(char * __restrict s1, const char * __restrict s2, size_t n)
  {
-  AsciiStrnCpyS (s1, n, s2, n);
+  AsciiStrnCpyS (s1, n + 1, s2, n);
    return s1;
    //char *dest = s1;
diff --git a/StdLib/LibC/Wchar/Copying.c b/StdLib/LibC/Wchar/Copying.c
index 45ceda7..d5a1149 100644
--- a/StdLib/LibC/Wchar/Copying.c
+++ b/StdLib/LibC/Wchar/Copying.c
@@ -44,7 +44,7 @@ wchar_t *wcscpy(wchar_t * __restrict s1, const wchar_t * 
__restrict s2)
  **/
  wchar_t *wcsncpy(wchar_t * __restrict s1, const wchar_t * __restrict s2, 
size_t n)
  {
-  return (wchar_t *)StrnCpyS ((CHAR16 *)s1, (UINTN)n, (CONST CHAR16 *)s2, 
(UINTN)n);
+  return (wchar_t *)StrnCpyS ((CHAR16 *)s1, (UINTN)n + 1, (CONST CHAR16 *)s2, 
(UINTN)n);
  }
/** The wmemcpy function copies n wide characters from the object pointed to by


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#80073): https://edk2.groups.io/g/devel/message/80073
Mute This Topic: https://groups.io/mt/85296459/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to