From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web12.4667.1630480750045099360 for ; Wed, 01 Sep 2021 00:19:11 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: michael.d.kinney@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10093"; a="282376313" X-IronPort-AV: E=Sophos;i="5.84,368,1620716400"; d="scan'208";a="282376313" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2021 00:19:08 -0700 X-IronPort-AV: E=Sophos;i="5.84,368,1620716400"; d="scan'208";a="531980762" Received: from mdkinney-mobl2.amr.corp.intel.com ([10.212.147.208]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2021 00:19:08 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Rebecca Cran , Jayaprakash Nevara Subject: [edk2-libc Patch] StdLib/LibC: Fix corner case in use of StrnCpyS() and AsciiStrnCpyS() Date: Wed, 1 Sep 2021 00:18:58 -0700 Message-Id: <20210901071858.1686-1-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.32.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Jayaprakash Nevara Signed-off-by: Michael D Kinney --- 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 -- 2.32.0.windows.1