Browse Source

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 <glin@suse.com>
Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
Gary Lin 6 years ago
parent
commit
ba250504b9
1 changed files with 7 additions and 2 deletions
  1. 7 2
      lib/runtime/rtstr.c

+ 7 - 2
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__