From patchwork Mon Oct 24 17:41:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 79023 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp2703291qge; Mon, 24 Oct 2016 10:42:25 -0700 (PDT) X-Received: by 10.98.93.83 with SMTP id r80mr30532531pfb.17.1477330945074; Mon, 24 Oct 2016 10:42:25 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id v4si9595267pgo.267.2016.10.24.10.42.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Oct 2016 10:42:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 381F81A1EC7; Mon, 24 Oct 2016 10:42:21 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x22d.google.com (mail-wm0-x22d.google.com [IPv6:2a00:1450:400c:c09::22d]) (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 D2AAD1A1E3E for ; Mon, 24 Oct 2016 10:42:18 -0700 (PDT) Received: by mail-wm0-x22d.google.com with SMTP id f193so135895949wmg.0 for ; Mon, 24 Oct 2016 10:42:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ioJs2vMsxMMoLeFg8uY45GTpGDzgbaLv6qjFTEFuluA=; b=jwhOfK7U2eWx0J2/IHNfwrhR0gfVYL4BevvZsvTtIV0Mu/4jpfN3eN1eQUIScC3dIC BtPloijYLne6e0BWsU/4NHY8Rcnm6XwYUCgXpFGgm8+DrYN7vT1atXfKkY9lUCmEAxln DPGYsQdC2W5Qp0iPxJqf7HtT1luztMoJOTtII= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ioJs2vMsxMMoLeFg8uY45GTpGDzgbaLv6qjFTEFuluA=; b=MlaivmRBaJa/JcueaKFV2hMjFcCv5LDNssZ1Uw3JObwxdrhqNfdM9tgxUxYTDsPVAQ gVBvVv/PwNig3ICNV9LAV+pvCnH7ywQXO3ir7T2pSjxwIYp4fmQLtNXAzbmKx436wwCt rhhp0Pb3MyhiXUZgNnNfktFwOmChzBbQeLrxxBncOEFE/xXesFJH3TyiHtpnK55h66Hg dpjskPLUED+Pu9E8A6XxcfhC4jhyvZvUZXCApBHdt4NP0uJ+7mlZgBzN+588qfsKeAUL Xi8vKORx+HkvKuuupZgSQ6o9/SUjczOovjf8l0msVoVxkWqEw/+yEccuqbZD4/VvbmsY /avQ== X-Gm-Message-State: ABUngve9e5yDLG3Oocn6S0WVoRxE0YnnZ0KtfYJxxyulCXggs8qYT9M5wTM54OlzXtB7ySuF X-Received: by 10.194.56.69 with SMTP id y5mr12961034wjp.4.1477330937414; Mon, 24 Oct 2016 10:42:17 -0700 (PDT) Received: from localhost.localdomain ([105.146.229.54]) by smtp.gmail.com with ESMTPSA id 194sm15894873wmj.20.2016.10.24.10.42.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Oct 2016 10:42:16 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org, lersek@redhat.com Date: Mon, 24 Oct 2016 18:41:45 +0100 Message-Id: <1477330907-13733-8-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477330907-13733-1-git-send-email-ard.biesheuvel@linaro.org> References: <1477330907-13733-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 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: , Cc: Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 --- EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c | 42 +++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Laszlo Ersek 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); } 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); }