From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x22c.google.com (mail-wm0-x22c.google.com [IPv6:2a00:1450:400c:c09::22c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 34ADB81DA7 for ; Fri, 28 Oct 2016 07:37:20 -0700 (PDT) Received: by mail-wm0-x22c.google.com with SMTP id p190so15089315wmp.1 for ; Fri, 28 Oct 2016 07:37:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HMYiiha8VZxxb7QsMaQP9iM6dTjqZMcFAaJJ7UXqHpM=; b=UQ7Ggu/QDS7ZLilXCg4h00Kx75n2ZmOOU8idE0hUN82Th/7z4chOM+i/A/glWf9K9Y s2y4S3R/me6lfUVQ0e1t+bNTz5SCxNnJx8LMmUDr1J4ICOdiC5Ifdl0vpsDaZmCzrqgJ AtvoFL+kdhnNaK7R+Y8baRsPAOGtJbvsp8x8E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HMYiiha8VZxxb7QsMaQP9iM6dTjqZMcFAaJJ7UXqHpM=; b=av11FMNY9GOPv558DS2xYLjK6iYyqXbtJnMjyr1I5Q1lQ4CSa6WNw/WJ2y/LllV7pT 3S2xG8+yXbxZjynz90tMEthjWbNioRerozmNagPhPrdWUGuyWUkv088rjExMFua8OcfR b6kGssspBbRu8obT5BufKRapxCC1MPJhp1m9Nj4K5J0XVv4C+1rtDyqenOtph9ra/RqJ xvzA5+7uv+PapweMFn37Fp5kmNfwSURIEXIYdkRCVZ2XzNx3ya+Ozh/v7AGChnoi9ayN Gc1DAlFg6MpWVn9JQBXs3WPKZIFKUdiahoOZiQ7kAyV1coJYi4fNQnOIER1r4XbspGKU QMFQ== X-Gm-Message-State: ABUngvcaUMwsR4gD1KqQd6Ck0FnET9aLL3GMMw25Vm3wyKWqU+rvDYVA60ODF382AtDURSr1 X-Received: by 10.28.135.84 with SMTP id j81mr3296279wmd.127.1477665439212; Fri, 28 Oct 2016 07:37:19 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id e5sm9243596wma.10.2016.10.28.07.37.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Oct 2016 07:37:18 -0700 (PDT) Date: Fri, 28 Oct 2016 15:37:16 +0100 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org, lersek@redhat.com, ryan.harkin@linaro.org Message-ID: <20161028143716.GQ1161@bivouac.eciton.net> References: <1477651478-16830-1-git-send-email-ard.biesheuvel@linaro.org> <1477651478-16830-8-git-send-email-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <1477651478-16830-8-git-send-email-ard.biesheuvel@linaro.org> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [PATCH v2 7/9] EmbeddedPkg/EfiFileLib: eliminate deprecated string function calls X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Oct 2016 14:37:20 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Oct 28, 2016 at 11:44:36AM +0100, Ard Biesheuvel wrote: > Get rid of calls to unsafe string functions. These are deprecated and may > be removed in the future. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ard Biesheuvel > Reviewed-by: Laszlo Ersek > --- > EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c | 42 +++++++++++--------- > 1 file changed, 23 insertions(+), 19 deletions(-) > > diff --git a/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c b/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c > index 4d58c830861c..d3b65aa5a3e0 100644 > --- a/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c > +++ b/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c > @@ -384,9 +384,9 @@ EblFileDevicePath ( > > > if ( *FileName != 0 ) { > - AsciiStrToUnicodeStr (FileName, UnicodeFileName); > + AsciiStrToUnicodeStrS (FileName, UnicodeFileName, MAX_PATHNAME); So, I could suggest ARRAY_SIZE again, but since the define here makes more semantic sense to begin with, it matters even less. Reviewed-by: Leif Lindholm > } else { > - AsciiStrToUnicodeStr ("\\", UnicodeFileName); > + AsciiStrToUnicodeStrS ("\\", UnicodeFileName, MAX_PATHNAME); > } > > Size = StrSize (UnicodeFileName); > @@ -589,7 +589,7 @@ EblFvFileDevicePath ( > &AuthenticationStatus > ); > if (!EFI_ERROR (Status)) { > - UnicodeStrToAsciiStr (Section, AsciiSection); > + UnicodeStrToAsciiStrS (Section, AsciiSection, MAX_PATHNAME); > if (AsciiStriCmp (FileName, AsciiSection) == 0) { > FreePool (Section); > break; > @@ -674,6 +674,7 @@ EfiOpen ( > CHAR8 *CwdPlusPathName; > UINTN Index; > EFI_SECTION_TYPE ModifiedSectionType; > + UINTN AsciiLength; > > EblUpdateDeviceLists (); > > @@ -706,7 +707,8 @@ EfiOpen ( > } > > // We could add a current working directory concept > - CwdPlusPathName = AllocatePool (AsciiStrSize (gCwd) + AsciiStrSize (PathName)); > + AsciiLength = AsciiStrSize (gCwd) + AsciiStrSize (PathName); > + CwdPlusPathName = AllocatePool (AsciiLength); > if (CwdPlusPathName == NULL) { > return NULL; > } > @@ -723,14 +725,14 @@ EfiOpen ( > } > } > } else { > - AsciiStrCpy (CwdPlusPathName, gCwd); > + AsciiStrCpyS (CwdPlusPathName, AsciiLength, gCwd); > StrLen = AsciiStrLen (gCwd); > if ((*PathName != '/') && (*PathName != '\\') && (gCwd[StrLen-1] != '/') && (gCwd[StrLen-1] != '\\')) { > - AsciiStrCat (CwdPlusPathName, "\\"); > + AsciiStrCatS (CwdPlusPathName, AsciiLength, "\\"); > } > } > > - AsciiStrCat (CwdPlusPathName, PathName); > + AsciiStrCatS (CwdPlusPathName, AsciiLength, PathName); > if (AsciiStrStr (CwdPlusPathName, ":") == NULL) { > // Extra error check to make sure we don't recurse and blow stack > return NULL; > @@ -745,7 +747,7 @@ EfiOpen ( > } > > File->DeviceName = AllocatePool (StrLen); > - AsciiStrCpy (File->DeviceName, PathName); > + AsciiStrCpyS (File->DeviceName, StrLen, PathName); > File->DeviceName[FileStart - 1] = '\0'; > File->FileName = &File->DeviceName[FileStart]; > if (File->FileName[0] == '\0') { > @@ -1611,7 +1613,7 @@ ExpandPath ( > { > CHAR8 *NewPath; > CHAR8 *Work, *Start, *End; > - UINTN StrLen; > + UINTN StrLen, AllocLen; > INTN i; > > if (Cwd == NULL || Path == NULL) { > @@ -1625,11 +1627,12 @@ ExpandPath ( > } > > StrLen = AsciiStrSize (Path); > - NewPath = AllocatePool (AsciiStrSize (Cwd) + StrLen + 1); > + AllocLen = AsciiStrSize (Cwd) + StrLen + 1; > + NewPath = AllocatePool (AllocLen); > if (NewPath == NULL) { > return NULL; > } > - AsciiStrCpy (NewPath, Cwd); > + AsciiStrCpyS (NewPath, AllocLen, Cwd); > > End = Path + StrLen; > for (Start = Path ;;) { > @@ -1640,7 +1643,7 @@ ExpandPath ( > } > > // append path prior to .. > - AsciiStrnCat (NewPath, Start, Work - Start); > + AsciiStrnCatS (NewPath, AllocLen, Start, Work - Start); > StrLen = AsciiStrLen (NewPath); > for (i = StrLen; i >= 0; i--) { > if (NewPath[i] == ':') { > @@ -1663,7 +1666,7 @@ ExpandPath ( > } > > // Handle the path that remains after the .. > - AsciiStrnCat (NewPath, Start, End - Start); > + AsciiStrnCatS (NewPath, AllocLen, Start, End - Start); > > return NewPath; > } > @@ -1686,7 +1689,7 @@ EfiSetCwd ( > ) > { > EFI_OPEN_FILE *File; > - UINTN Len; > + UINTN Len, AllocLen; > CHAR8 *Path; > > if (Cwd == NULL) { > @@ -1729,17 +1732,18 @@ EfiSetCwd ( > > // Use the info returned from EfiOpen as it can add in CWD if needed. So Cwd could be > // relative to the current gCwd or not. > - gCwd = AllocatePool (AsciiStrSize (File->DeviceName) + AsciiStrSize (File->FileName) + 10); > + AllocLen = AsciiStrSize (File->DeviceName) + AsciiStrSize (File->FileName) + 10; > + gCwd = AllocatePool (AllocLen); > if (gCwd == NULL) { > return EFI_INVALID_PARAMETER; > } > > - AsciiStrCpy (gCwd, File->DeviceName); > + AsciiStrCpyS (gCwd, AllocLen, File->DeviceName); > if (File->FileName == NULL) { > - AsciiStrCat (gCwd, ":\\"); > + AsciiStrCatS (gCwd, AllocLen, ":\\"); > } else { > - AsciiStrCat (gCwd, ":"); > - AsciiStrCat (gCwd, File->FileName); > + AsciiStrCatS (gCwd, AllocLen, ":"); > + AsciiStrCatS (gCwd, AllocLen, File->FileName); > } > > > -- > 2.7.4 >