From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by mx.groups.io with SMTP id smtpd.web12.7913.1630502656091713893 for ; Wed, 01 Sep 2021 06:24:16 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=2J0gCaAC; spf=pass (domain: nuviainc.com, ip: 209.85.222.174, mailfrom: rebecca@nuviainc.com) Received: by mail-qk1-f174.google.com with SMTP id w78so1808001qkb.4 for ; Wed, 01 Sep 2021 06:24:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=MVbL5EqhPSwW0JYbEOqzzZtUSpRM/YdUvKOAnVOtnKQ=; b=2J0gCaACmfhT6p3LEdR3Gs+w175VQ/1jxuV0iD/4oTlTfs96d625TSas+5TRviiCNG aprQgUGQiQTG+LVzfT9lwq0Zt/0tJOvMZv08AVK7EsUgHvW2VvgIYVJV6CRRhHab0eql UuEo7TPi0pzWGE/Xhr6PcLjAWfkrbktG5xeiTiIEn/NNrua8P2yl65jdu9hMOS1+cgqB 7fO7AGhrAv/PiPioCY2i6avEjpYPLiK7ol7U6+/6XmWcMz2bJsOoEHW0iUhXmV5i3s5f DGZRuHo4/BKLbzpW8zRzDnB1rr3Pg5pZniCHDtdpNBTlQIufR4IfkZHQZoyqfmzbt9ZC 3wrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=MVbL5EqhPSwW0JYbEOqzzZtUSpRM/YdUvKOAnVOtnKQ=; b=S8HdKYR0MdWFPERwe3k3NXYv7vhVf7zBErEJi1a/q7NEdUVFHEMJBCxwo2gmgeVEGt 1fwWJZLrcPRXwq/nhD6Qz2DgRK34C+3ABWlVxwFR2Uf7Xob8IKam06bS8JILCoNNBV2K Kjt/xjCi/ucoGvhwJ3P5IX4TvA8ATb58OEZI6GARVRK5298lmpYBqAmmxZw2X0V3Zb0i 4AO0JIKfWfNmzkjllh6X8p1T5uQicbemh+VjhbpA/zE335D/7eg7ytz+iYdhYM+v8A1V CEg181+tiajz7oKcPtfpd5h8A3bSvcfVECvDuY423jgnP06auCVyhSyeBjPz5q671kqF uTXg== X-Gm-Message-State: AOAM5323sJf7bVGpOO0aE++XPtP6z1wWHBWzm6Aw3OeVbgTJsCSDrQYE NUV5tpuzNh5ED4nCMmEMxTfvNg== X-Google-Smtp-Source: ABdhPJw3ZmtsUQ3gkKcBACiWeBAuXYvqehN84UefW0qrRN7cOKwMkZQonYpetv7+aKKzaDzUyRFvRA== X-Received: by 2002:a05:620a:1402:: with SMTP id d2mr8414302qkj.141.1630502655126; Wed, 01 Sep 2021 06:24:15 -0700 (PDT) Return-Path: Received: from linbox.int.bluestop.org (c-174-52-16-57.hsd1.ut.comcast.net. [174.52.16.57]) by smtp.gmail.com with ESMTPSA id d78sm16444230qkg.92.2021.09.01.06.24.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Sep 2021 06:24:14 -0700 (PDT) Subject: Re: [edk2-libc Patch] StdLib/LibC: Fix corner case in use of StrnCpyS() and AsciiStrnCpyS() To: Michael D Kinney , devel@edk2.groups.io Cc: Jayaprakash Nevara References: <20210901071858.1686-1-michael.d.kinney@intel.com> From: "Rebecca Cran" Message-ID: <3c89308c-dab5-3a48-267e-7b88e2c31875@nuviainc.com> Date: Wed, 1 Sep 2021 07:24:13 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210901071858.1686-1-michael.d.kinney@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Reviewed-by: Rebecca Cran -- 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 > 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