]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmbeddedPkg/AndroidFastboot: eliminate deprecated string function calls
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 24 Oct 2016 17:29:35 +0000 (18:29 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 28 Oct 2016 12:51:45 +0000 (13:51 +0100)
Get rid of calls to unsafe string functions. These are deprecated and may
be removed in the future.

Note that this also addresses a latent potential issue in HandleDownload(),
where NumBytesString[] (which comes from the wire) is assumed to contain a
string representation of a number with all the significant digits in the
first 8 bytes, which is not guaranteed by the protocol.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c
EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.c

index bbca90fc08a205582f9cace0da528b825d2d063c..f3e770bcc98028d7b54623ca2daf57c5514773b6 100644 (file)
@@ -84,7 +84,8 @@ ParseAndroidBootImg (
                  + ALIGN_VALUE (Header->KernelSize, Header->PageSize));\r
   }\r
 \r
-  AsciiStrnCpy (KernelArgs, Header->KernelArgs, BOOTIMG_KERNEL_ARGS_SIZE);\r
+  AsciiStrnCpyS (KernelArgs, BOOTIMG_KERNEL_ARGS_SIZE, Header->KernelArgs,\r
+    BOOTIMG_KERNEL_ARGS_SIZE);\r
 \r
   return EFI_SUCCESS;\r
 }\r
index 9ddc34f57cf4448a86926dc9270d95c7d8a83520..c5e8a7e34af2048151eeb826dd24c9225043ff54 100644 (file)
@@ -99,7 +99,7 @@ HandleDownload (
   IN CHAR8 *NumBytesString\r
   )\r
 {\r
-  CHAR8       Response[12] = "DATA";\r
+  CHAR8       Response[13];\r
   CHAR16      OutputString[FASTBOOT_STRING_MAX_LENGTH];\r
 \r
   // Argument is 8-character ASCII string hex representation of number of bytes\r
@@ -127,8 +127,10 @@ HandleDownload (
   if (mDataBuffer == NULL) {\r
     SEND_LITERAL ("FAILNot enough memory");\r
   } else {\r
-    AsciiStrnCpy (Response + 4, NumBytesString, 8);\r
-    mTransport->Send (sizeof(Response), Response, &mFatalSendErrorEvent);\r
+    ZeroMem (Response, sizeof Response);\r
+    AsciiSPrint (Response, sizeof Response, "DATA%x",\r
+      (UINT32)mNumDataBytes);\r
+    mTransport->Send (sizeof Response - 1, Response, &mFatalSendErrorEvent);\r
 \r
     mState = ExpectDataState;\r
     mBytesReceivedSoFar = 0;\r
@@ -257,8 +259,7 @@ AcceptCmd (
   }\r
 \r
   // Commands aren't null-terminated. Let's get a null-terminated version.\r
-  AsciiStrnCpy (Command, Data, Size);\r
-  Command[Size] = '\0';\r
+  AsciiStrnCpyS (Command, sizeof Command, Data, Size);\r
 \r
   // Parse command\r
   if (MATCH_CMD_LITERAL ("getvar", Command)) {\r