From ba250504b9bba87d062ff8da6a7839433f108ce4 Mon Sep 17 00:00:00 2001 From: Gary Lin Date: Thu, 11 Oct 2018 12:02:27 +0800 Subject: [PATCH] Implement StrnCat() without StrnCpy() StrnCpy() doesn't guarantee the dest string will be null-terminated, so we shouldn't use StrnCpy(). Signed-off-by: Gary Lin Signed-off-by: Nigel Croxon --- lib/runtime/rtstr.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/runtime/rtstr.c b/lib/runtime/rtstr.c index 65cc018..129c9f2 100644 --- a/lib/runtime/rtstr.c +++ b/lib/runtime/rtstr.c @@ -126,7 +126,7 @@ RtStrCat ( } #ifndef __GNUC__ -#pragma RUNTIME_CODE(RtStrCat) +#pragma RUNTIME_CODE(RtStrnCat) #endif VOID RUNTIMEFUNCTION @@ -136,7 +136,12 @@ RtStrnCat ( IN UINTN Len ) { - RtStrnCpy(Dest+StrLen(Dest), Src, Len); + UINTN DestSize, Size; + + DestSize = StrLen(Dest); + Size = RtStrnLen(Src, Len); + RtCopyMem(Dest + DestSize, Src, Size * sizeof(CHAR16)); + Dest[DestSize + Size] = '\0'; } #ifndef __GNUC__