aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2024-12-19 10:19:29 -0600
committerTom Rini <trini@konsulko.com>2024-12-19 10:19:29 -0600
commit1688f8474538e5e8289897ecdcba2964cabb4a10 (patch)
tree23e7d4eec8a565b6a5f94a0ae554a291769d6ab3
parent69bd83568c57813cd23bc2d100c066a17e7e349d (diff)
parent9e5fad0f792539ae4258bc116bf408bb6faf7e82 (diff)
downloadu-boot-1688f8474538e5e8289897ecdcba2964cabb4a10.zip
u-boot-1688f8474538e5e8289897ecdcba2964cabb4a10.tar.gz
u-boot-1688f8474538e5e8289897ecdcba2964cabb4a10.tar.bz2
Merge tag 'u-boot-dfu-20241219' of https://source.denx.de/u-boot/custodians/u-boot-dfu
CI: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/23951 Android: - Fix kcmdline_extra support when parsing boot image - Fix memory leak when after bootargs concatenation - Fix length calculation when merging bootargs, cmdline and kcmdline
-rw-r--r--boot/image-android.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/boot/image-android.c b/boot/image-android.c
index cd01278..61ac312 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -287,41 +287,45 @@ int android_image_get_kernel(const void *hdr,
kernel_addr, DIV_ROUND_UP(img_data.kernel_size, 1024));
int len = 0;
+ char *bootargs = env_get("bootargs");
+
+ if (bootargs)
+ len += strlen(bootargs);
+
if (*img_data.kcmdline) {
printf("Kernel command line: %s\n", img_data.kcmdline);
- len += strlen(img_data.kcmdline);
+ len += strlen(img_data.kcmdline) + (len ? 1 : 0); /* +1 for extra space */
}
- if (img_data.kcmdline_extra) {
+ if (*img_data.kcmdline_extra) {
printf("Kernel extra command line: %s\n", img_data.kcmdline_extra);
- len += strlen(img_data.kcmdline_extra);
+ len += strlen(img_data.kcmdline_extra) + (len ? 1 : 0); /* +1 for extra space */
}
- char *bootargs = env_get("bootargs");
- if (bootargs)
- len += strlen(bootargs);
-
- char *newbootargs = malloc(len + 2);
+ char *newbootargs = malloc(len + 1); /* +1 for the '\0' */
if (!newbootargs) {
puts("Error: malloc in android_image_get_kernel failed!\n");
return -ENOMEM;
}
- *newbootargs = '\0';
+ *newbootargs = '\0'; /* set to Null in case no components below are present */
- if (bootargs) {
+ if (bootargs)
strcpy(newbootargs, bootargs);
- strcat(newbootargs, " ");
- }
- if (*img_data.kcmdline)
+ if (*img_data.kcmdline) {
+ if (*newbootargs) /* If there is something in newbootargs, a space is needed */
+ strcat(newbootargs, " ");
strcat(newbootargs, img_data.kcmdline);
+ }
- if (img_data.kcmdline_extra) {
- strcat(newbootargs, " ");
+ if (*img_data.kcmdline_extra) {
+ if (*newbootargs) /* If there is something in newbootargs, a space is needed */
+ strcat(newbootargs, " ");
strcat(newbootargs, img_data.kcmdline_extra);
}
env_set("bootargs", newbootargs);
+ free(newbootargs);
if (os_data) {
if (image_get_magic(ihdr) == IH_MAGIC) {