From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw0-x234.google.com (mail-yw0-x234.google.com [IPv6:2607:f8b0:4002:c05::234]) (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 D82C681D88 for ; Fri, 28 Oct 2016 06:41:00 -0700 (PDT) Received: by mail-yw0-x234.google.com with SMTP id h14so85952484ywa.2 for ; Fri, 28 Oct 2016 06:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=FVrgWlvTL5SAB02mR2VtA3UKXg+kphu/bjG7sFup3OQ=; b=GjQUNsVm7YwxlIB7X01yzAlgfLXCpB4kQFS1V0F3QFPBwFb4Arcrs77Fj6EDPD5zya Hw+gWPDqgE6fw9+q6RJvbKbLx3mLqpe19gxxOGLVQUfsfR7YsnNClpidld/H/15fa7KC IBUV1KhiyVm6JHMuUDQQBzREntVPR7UbzB8N0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=FVrgWlvTL5SAB02mR2VtA3UKXg+kphu/bjG7sFup3OQ=; b=Ip3iXNnI/IkvmO86bG34lkTyE58ZFAyy5lT5SZcc+RvFQ11/WlFEy89womMfoAJiUB IQ0djyBV3x2kkz6Qd8I7v1WV07uy1yqMnCrfFO3USYc69XBS1CuD/5HSjxgSp2+6bMZp I2ie3IWiVoter5KOBwsFWeUDrOt2Hh4dbWjHe9YQ4KU5G7ItKBj9VpSv1ceW57deq7EV /v8OpzWQnRFPDUkX+YU6BHftphjPX+8EP12gwMDi/kF24eeStE5v0NWgkgQ5inKE77e/ GCUGyN5h6NUqvHmDjyOT/7z8+xOB06vpQxOocdPcughQzMCPATPV9ajPnTXP2nDQRJXG 0JwQ== X-Gm-Message-State: ABUngvdUQeRG3vG8PAvmxEYg4OlebPx4s1bf1BjezPJsq+MSupoLVFHhcm45su8O8owZbvDvbq2cFFstlKsw5dGD X-Received: by 10.36.146.84 with SMTP id l81mr2547983itd.37.1477662060280; Fri, 28 Oct 2016 06:41:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.5.139 with HTTP; Fri, 28 Oct 2016 06:40:59 -0700 (PDT) In-Reply-To: <20161028133625.GM1161@bivouac.eciton.net> References: <1477651478-16830-1-git-send-email-ard.biesheuvel@linaro.org> <1477651478-16830-6-git-send-email-ard.biesheuvel@linaro.org> <20161028133625.GM1161@bivouac.eciton.net> From: Ard Biesheuvel Date: Fri, 28 Oct 2016 14:40:59 +0100 Message-ID: To: Leif Lindholm Cc: edk2-devel-01 , Laszlo Ersek , Ryan Harkin Subject: Re: [PATCH v2 5/9] EmbeddedPkg/AndroidFastboot: 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 13:41:01 -0000 Content-Type: text/plain; charset=UTF-8 On 28 October 2016 at 14:36, Leif Lindholm wrote: > On Fri, Oct 28, 2016 at 11:44:34AM +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/Application/AndroidFastboot/AndroidBootImg.c | 3 ++- >> EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.c | 11 ++++++----- >> 2 files changed, 8 insertions(+), 6 deletions(-) >> >> diff --git a/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c b/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c >> index bbca90fc08a2..f3e770bcc980 100644 >> --- a/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c >> +++ b/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c >> @@ -84,7 +84,8 @@ ParseAndroidBootImg ( >> + ALIGN_VALUE (Header->KernelSize, Header->PageSize)); >> } >> >> - AsciiStrnCpy (KernelArgs, Header->KernelArgs, BOOTIMG_KERNEL_ARGS_SIZE); >> + AsciiStrnCpyS (KernelArgs, BOOTIMG_KERNEL_ARGS_SIZE, Header->KernelArgs, >> + BOOTIMG_KERNEL_ARGS_SIZE); >> >> return EFI_SUCCESS; >> } >> diff --git a/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.c b/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.c >> index 9ddc34f57cf4..c5e8a7e34af2 100644 >> --- a/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.c >> +++ b/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.c >> @@ -99,7 +99,7 @@ HandleDownload ( >> IN CHAR8 *NumBytesString >> ) >> { >> - CHAR8 Response[12] = "DATA"; >> + CHAR8 Response[13]; >> CHAR16 OutputString[FASTBOOT_STRING_MAX_LENGTH]; >> >> // Argument is 8-character ASCII string hex representation of number of bytes >> @@ -127,8 +127,10 @@ HandleDownload ( >> if (mDataBuffer == NULL) { >> SEND_LITERAL ("FAILNot enough memory"); >> } else { >> - AsciiStrnCpy (Response + 4, NumBytesString, 8); >> - mTransport->Send (sizeof(Response), Response, &mFatalSendErrorEvent); >> + ZeroMem (Response, sizeof Response); >> + AsciiSPrint (Response, sizeof Response, "DATA%x", >> + (UINT32)mNumDataBytes); > > I'll try to keep the bikeshedding to a minimum, but since > mNumDataBytes is generated from NumBytesString in the first place, why > not do > "DATA%s", NumBytesString > ? > Are you asking me? Or the author of the original code? >> + mTransport->Send (sizeof Response - 1, Response, &mFatalSendErrorEvent); >> >> mState = ExpectDataState; >> mBytesReceivedSoFar = 0; >> @@ -257,8 +259,7 @@ AcceptCmd ( >> } >> >> // Commands aren't null-terminated. Let's get a null-terminated version. >> - AsciiStrnCpy (Command, Data, Size); >> - Command[Size] = '\0'; >> + AsciiStrnCpyS (Command, sizeof Command, Data, Size); >> >> // Parse command >> if (MATCH_CMD_LITERAL ("getvar", Command)) { >> -- >> 2.7.4 >>