From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x233.google.com (mail-wm0-x233.google.com [IPv6:2a00:1450:400c:c09::233]) (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 3965A81DA0 for ; Fri, 28 Oct 2016 07:32:02 -0700 (PDT) Received: by mail-wm0-x233.google.com with SMTP id 140so78350036wmv.0 for ; Fri, 28 Oct 2016 07:32:02 -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=YnMESH0SWwNCET7DrYRi8g6/LLWZHZC3e+TR/uigfTk=; b=WJ0Hw0HdNWV8+FQNSLo+xY2OYwBmlwk3Bln8o6oJHogOgC02uhuFJ6k6QPpngLjZXM 2bhprTywHE9m+VMsq0hiqXsxaUQ6iLG6M3FYYxPbr0OXSGWwydJU16ZlYR087jedzER8 NVWkn0cGaYc6ChgxQg9mfNgMvSsra28DqdeQc= 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=YnMESH0SWwNCET7DrYRi8g6/LLWZHZC3e+TR/uigfTk=; b=aaSap9RuQo7QLPvCfsgndiHqwEYG//yJlnQhd3u/G1n1gT4vvHdKALizXFizJdWZOe x929fOoRiFdBFhHS4QYE7B1XPuurigP93YhtbMfES3c/Vd3oFy5UkESYki1IOhNeN1JQ 2aIQKTicH/eB8XegqBglI5OqcqXOcdJFub5vhMq8MK/yoLy7mWu+JALo2oSiy2NEcX/0 1cp1Jev0UaF06wBOuHyudrMXo+VEOEsRNnzqKirlZl/9icMUa92Id7A2MR3U/CSNS/HM DRMTM7uY0+IitC4rFE7W8btRGQPCD3lp03QspF+AFWgF/y4CDwZSXxyrPwiN8P6m5K5G RZVg== X-Gm-Message-State: ABUngvd0PS8RWnalk+2VUa2ZQtyA6YITzIAaC0fOz7doqIPu9P6lSPQUxexBHXotzczJNj3w X-Received: by 10.195.11.166 with SMTP id ej6mr2404137wjd.60.1477665115107; Fri, 28 Oct 2016 07:31:55 -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 xq9sm14413759wjb.35.2016.10.28.07.31.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Oct 2016 07:31:54 -0700 (PDT) Date: Fri, 28 Oct 2016 15:31:52 +0100 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org, lersek@redhat.com, ryan.harkin@linaro.org Message-ID: <20161028143152.GP1161@bivouac.eciton.net> References: <1477651478-16830-1-git-send-email-ard.biesheuvel@linaro.org> <1477651478-16830-7-git-send-email-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <1477651478-16830-7-git-send-email-ard.biesheuvel@linaro.org> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [PATCH v2 6/9] EmbeddedPkg/Ebl: 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:32:02 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Oct 28, 2016 at 11:44:35AM +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 > --- > EmbeddedPkg/Ebl/Command.c | 2 +- > EmbeddedPkg/Ebl/Dir.c | 4 ++-- > EmbeddedPkg/Ebl/EfiDevice.c | 11 ++++++----- > EmbeddedPkg/Ebl/Main.c | 8 ++++---- > EmbeddedPkg/Ebl/Variable.c | 17 +++++++++++------ > 5 files changed, 24 insertions(+), 18 deletions(-) > > diff --git a/EmbeddedPkg/Ebl/Command.c b/EmbeddedPkg/Ebl/Command.c > index e75c6a2e5c32..4bc1f4df0ca0 100644 > --- a/EmbeddedPkg/Ebl/Command.c > +++ b/EmbeddedPkg/Ebl/Command.c > @@ -614,7 +614,7 @@ OutputData ( > UINTN Spaces = 0; > CHAR8 Blanks[80]; > > - AsciiStrCpy (Blanks, mBlanks); > + AsciiStrCpyS (Blanks, sizeof Blanks, mBlanks); > for (EndAddress = Address + Length; Address < EndAddress; Offset += Line) { > AsciiPrint ("%08x: ", Offset); > for (Line = 0; (Line < 0x10) && (Address < EndAddress);) { > diff --git a/EmbeddedPkg/Ebl/Dir.c b/EmbeddedPkg/Ebl/Dir.c > index 36095b633019..8dd9d48ff6ac 100644 > --- a/EmbeddedPkg/Ebl/Dir.c > +++ b/EmbeddedPkg/Ebl/Dir.c > @@ -116,7 +116,7 @@ EblDirCmd ( > UnicodeFileName[0] = '\0'; > MatchSubString = &UnicodeFileName[0]; > if (Argc > 2) { > - AsciiStrToUnicodeStr (Argv[2], UnicodeFileName); > + AsciiStrToUnicodeStrS (Argv[2], UnicodeFileName, MAX_CMD_LINE); Actually (more bikeshedding, sorry), as Laszlo just pointed out ARRAY_SIZE, could we have ARRAY_SIZE(UnicodeFileName) in this function instead? Anyway, that's a suggestion, not a demand. Either way: Reviewed-by: Leif Lindholm > if (UnicodeFileName[0] == '*') { > // Handle *Name substring matching > MatchSubString = &UnicodeFileName[1]; > @@ -231,7 +231,7 @@ EblDirCmd ( > MatchSubString = NULL; > UnicodeFileName[0] = '\0'; > if (Argc > 2) { > - AsciiStrToUnicodeStr (Argv[2], UnicodeFileName); > + AsciiStrToUnicodeStrS (Argv[2], UnicodeFileName, MAX_CMD_LINE); > if (UnicodeFileName[0] == '*') { > MatchSubString = &UnicodeFileName[1]; > } > diff --git a/EmbeddedPkg/Ebl/EfiDevice.c b/EmbeddedPkg/Ebl/EfiDevice.c > index ec9c331b7004..f6969e7b2b05 100644 > --- a/EmbeddedPkg/Ebl/EfiDevice.c > +++ b/EmbeddedPkg/Ebl/EfiDevice.c > @@ -343,7 +343,7 @@ EblStartCmd ( > > ImageInfo->LoadOptionsSize = (UINT32)AsciiStrSize (Argv[2]); > ImageInfo->LoadOptions = AllocatePool (ImageInfo->LoadOptionsSize); > - AsciiStrCpy (ImageInfo->LoadOptions, Argv[2]); > + AsciiStrCpyS (ImageInfo->LoadOptions, ImageInfo->LoadOptionsSize, Argv[2]); > } > > // Transfer control to the EFI image we loaded with LoadImage() > @@ -741,7 +741,7 @@ EblFileCopyCmd ( > UINTN Size; > UINTN Offset; > UINTN Chunk = FILE_COPY_CHUNK; > - UINTN FileNameLen; > + UINTN FileNameLen, DestFileNameLen; > CHAR8* DestFileName; > CHAR8* SrcFileName; > CHAR8* SrcPtr; > @@ -786,9 +786,10 @@ EblFileCopyCmd ( > } > > // Construct the destination filepath > - DestFileName = (CHAR8*)AllocatePool (FileNameLen + AsciiStrLen (SrcFileName) + 1); > - AsciiStrCpy (DestFileName, Argv[2]); > - AsciiStrCat (DestFileName, SrcFileName); > + DestFileNameLen = FileNameLen + AsciiStrLen (SrcFileName) + 1; > + DestFileName = (CHAR8*)AllocatePool (DestFileNameLen); > + AsciiStrCpyS (DestFileName, DestFileNameLen, Argv[2]); > + AsciiStrCatS (DestFileName, DestFileNameLen, SrcFileName); > } > > Source = EfiOpen(Argv[1], EFI_FILE_MODE_READ, 0); > diff --git a/EmbeddedPkg/Ebl/Main.c b/EmbeddedPkg/Ebl/Main.c > index 18b2878f69a1..62f559fccfe8 100644 > --- a/EmbeddedPkg/Ebl/Main.c > +++ b/EmbeddedPkg/Ebl/Main.c > @@ -88,7 +88,7 @@ SetCmdHistory ( > } > > // Copy the new command line into the ring buffer > - AsciiStrnCpy(&mCmdHistory[mCmdHistoryStart][0], Cmd, MAX_CMD_LINE); > + AsciiStrnCpyS (&mCmdHistory[mCmdHistoryStart][0], MAX_CMD_LINE, Cmd, MAX_CMD_LINE); > } > > // Reset the command history for the next up arrow press > @@ -432,7 +432,7 @@ GetCmd ( > } > AsciiPrint (History); > Index = AsciiStrLen (History); > - AsciiStrnCpy (Cmd, History, CmdMaxSize); > + AsciiStrnCpyS (Cmd, CmdMaxSize, History, CmdMaxSize); > } else { > Cmd[Index++] = Char; > if (FixedPcdGetBool(PcdEmbeddedShellCharacterEcho) == TRUE) { > @@ -644,14 +644,14 @@ EdkBootLoaderEntry ( > > Status = gRT->GetVariable(CommandLineVariableName, &VendorGuid, NULL, &CommandLineVariableSize, CommandLineVariable); > if (!EFI_ERROR(Status)) { > - UnicodeStrToAsciiStr(CommandLineVariable, CmdLine); > + UnicodeStrToAsciiStrS (CommandLineVariable, CmdLine, MAX_CMD_LINE); > } > > FreePool(CommandLineVariable); > } > > if (EFI_ERROR(Status)) { > - AsciiStrCpy (CmdLine, (CHAR8 *)PcdGetPtr (PcdEmbeddedAutomaticBootCommand)); > + AsciiStrCpyS (CmdLine, MAX_CMD_LINE, (CHAR8 *)PcdGetPtr (PcdEmbeddedAutomaticBootCommand)); > } > > for (;;) { > diff --git a/EmbeddedPkg/Ebl/Variable.c b/EmbeddedPkg/Ebl/Variable.c > index f440c48f16dd..92464a6b7133 100644 > --- a/EmbeddedPkg/Ebl/Variable.c > +++ b/EmbeddedPkg/Ebl/Variable.c > @@ -29,6 +29,7 @@ EblGetCmd ( > VOID* Value; > CHAR8* AsciiVariableName = NULL; > CHAR16* VariableName; > + UINTN VariableNameLen; > UINT32 Index; > > if (Argc == 1) { > @@ -48,8 +49,9 @@ EblGetCmd ( > AsciiPrint("Variable name is missing.\n"); > return Status; > } else { > - VariableName = AllocatePool((AsciiStrLen (AsciiVariableName) + 1) * sizeof (CHAR16)); > - AsciiStrToUnicodeStr (AsciiVariableName,VariableName); > + VariableNameLen = AsciiStrLen (AsciiVariableName) + 1; > + VariableName = AllocatePool (VariableNameLen * sizeof (CHAR16)); > + AsciiStrToUnicodeStrS (AsciiVariableName, VariableName, VariableNameLen); > } > > // Try to get the variable size. > @@ -93,6 +95,7 @@ EblSetCmd ( > CHAR8* AsciiValue; > UINT32 AsciiValueLength; > CHAR16* VariableName; > + UINTN VariableNameLen; > UINT32 Index; > UINT32 EscapedQuotes = 0; > BOOLEAN Volatile = FALSE; > @@ -125,8 +128,9 @@ EblSetCmd ( > // > > // Convert VariableName into Unicode > - VariableName = AllocatePool((AsciiStrLen (AsciiVariableSetting) + 1) * sizeof (CHAR16)); > - AsciiStrToUnicodeStr (AsciiVariableSetting,VariableName); > + VariableNameLen = AsciiStrLen (AsciiVariableSetting) + 1; > + VariableName = AllocatePool (VariableNameLen * sizeof (CHAR16)); > + AsciiStrToUnicodeStrS (AsciiVariableSetting, VariableName, VariableNameLen); > > Status = gRT->SetVariable ( > VariableName, > @@ -170,8 +174,9 @@ EblSetCmd ( > } > > // Convert VariableName into Unicode > - VariableName = AllocatePool((AsciiStrLen (AsciiVariableName) + 1) * sizeof (CHAR16)); > - AsciiStrToUnicodeStr (AsciiVariableName,VariableName); > + VariableNameLen = AsciiStrLen (AsciiVariableName) + 1; > + VariableName = AllocatePool (VariableNameLen * sizeof (CHAR16)); > + AsciiStrToUnicodeStrS (AsciiVariableName, VariableName, VariableNameLen); > > Status = gRT->SetVariable ( > VariableName, > -- > 2.7.4 >