summaryrefslogtreecommitdiffstats
path: root/EmbeddedPkg
diff options
context:
space:
mode:
authorAshish Singhal <ashishsingha@nvidia.com>2023-11-29 20:44:13 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-11-30 04:58:07 +0000
commitc0207583e02205cf4dfda08fd102ebdb3df0b4f2 (patch)
tree9518b22c3a29d1c415bc79adc6e914f8dd83dea4 /EmbeddedPkg
parent4f99b5fb936a2a0239d5212948b7104d75d1558c (diff)
downloadedk2-c0207583e02205cf4dfda08fd102ebdb3df0b4f2.tar.gz
edk2-c0207583e02205cf4dfda08fd102ebdb3df0b4f2.tar.bz2
edk2-c0207583e02205cf4dfda08fd102ebdb3df0b4f2.zip
EmbeddedPkg: Fix Android Boot Command Line Length Bug
Curently, AndroidBootImgLib expects input kernel command line to never exceed 256 unicode characters where the image header allows for 512 ascii characters. If image header allows 512 ascii characters, similar number of unicode characters should be allowed at the minimum. Signed-off-by: Ashish Singhal <ashishsingha@nvidia.com> Reviewed-by: Abner Chang <abner.chang@amd.com>
Diffstat (limited to 'EmbeddedPkg')
-rw-r--r--EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c
index 1359a66db2..f63648e60d 100644
--- a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c
+++ b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c
@@ -322,11 +322,12 @@ AndroidBootImgGetFdt (
EFI_STATUS
AndroidBootImgUpdateArgs (
IN VOID *BootImg,
- OUT VOID *KernelArgs
+ OUT VOID **KernelArgs
)
{
CHAR8 ImageKernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE];
EFI_STATUS Status;
+ UINT32 NewKernelArgSize;
// Get kernel arguments from Android boot image
Status = AndroidBootImgGetKernelArgs (BootImg, ImageKernelArgs);
@@ -334,16 +335,23 @@ AndroidBootImgUpdateArgs (
return Status;
}
+ NewKernelArgSize = ANDROID_BOOTIMG_KERNEL_ARGS_SIZE;
+ *KernelArgs = AllocateZeroPool (sizeof (CHAR16) * NewKernelArgSize);
+ if (*KernelArgs == NULL) {
+ DEBUG ((DEBUG_ERROR, "Fail to allocate memory\n"));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
AsciiStrToUnicodeStrS (
ImageKernelArgs,
- KernelArgs,
- ANDROID_BOOTIMG_KERNEL_ARGS_SIZE >> 1
+ *KernelArgs,
+ NewKernelArgSize
);
// Append platform kernel arguments
if (mAndroidBootImg->AppendArgs) {
Status = mAndroidBootImg->AppendArgs (
- KernelArgs,
- ANDROID_BOOTIMG_KERNEL_ARGS_SIZE
+ *KernelArgs,
+ NewKernelArgSize
);
}
@@ -616,6 +624,10 @@ AndroidBootImgBoot (
UINTN RamdiskSize;
IN VOID *FdtBase;
+ if ((Buffer == NULL) || (BufferSize == 0)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
NewKernelArg = NULL;
ImageHandle = NULL;
@@ -637,14 +649,7 @@ AndroidBootImgBoot (
goto Exit;
}
- NewKernelArg = AllocateZeroPool (ANDROID_BOOTIMG_KERNEL_ARGS_SIZE);
- if (NewKernelArg == NULL) {
- DEBUG ((DEBUG_ERROR, "Fail to allocate memory\n"));
- Status = EFI_OUT_OF_RESOURCES;
- goto Exit;
- }
-
- Status = AndroidBootImgUpdateArgs (Buffer, NewKernelArg);
+ Status = AndroidBootImgUpdateArgs (Buffer, &NewKernelArg);
if (EFI_ERROR (Status)) {
goto Exit;
}