Skip to content
Snippets Groups Projects
Commit 9e5fad0f authored by Nicolas Belin's avatar Nicolas Belin Committed by Mattijs Korpershoek
Browse files

boot: android: rework bootargs concatenation


Rework the bootargs concatenation allocating more accurately
the length that is needed.
Do not forget an extra byte for the null termination byte as,
in some cases, the allocation was 1 byte short.

Fixes: 86f4695b ("image: Fix Android boot image support")
Signed-off-by: default avatarNicolas Belin <nbelin@baylibre.com>
Reviewed-by: default avatarMattijs Korpershoek <mkorpershoek@baylibre.com>
Link: https://lore.kernel.org/r/20241217-fix-bootargs-concatenation-v2-3-b2fd7cf4e130@baylibre.com


Signed-off-by: default avatarMattijs Korpershoek <mkorpershoek@baylibre.com>
parent fd8b44a8
No related branches found
No related tags found
No related merge requests found
...@@ -287,37 +287,40 @@ int android_image_get_kernel(const void *hdr, ...@@ -287,37 +287,40 @@ int android_image_get_kernel(const void *hdr,
kernel_addr, DIV_ROUND_UP(img_data.kernel_size, 1024)); kernel_addr, DIV_ROUND_UP(img_data.kernel_size, 1024));
int len = 0; int len = 0;
char *bootargs = env_get("bootargs");
if (bootargs)
len += strlen(bootargs);
if (*img_data.kcmdline) { if (*img_data.kcmdline) {
printf("Kernel command line: %s\n", 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); 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"); char *newbootargs = malloc(len + 1); /* +1 for the '\0' */
if (bootargs)
len += strlen(bootargs);
char *newbootargs = malloc(len + 2);
if (!newbootargs) { if (!newbootargs) {
puts("Error: malloc in android_image_get_kernel failed!\n"); puts("Error: malloc in android_image_get_kernel failed!\n");
return -ENOMEM; return -ENOMEM;
} }
*newbootargs = '\0'; *newbootargs = '\0'; /* set to Null in case no components below are present */
if (bootargs) { if (bootargs)
strcpy(newbootargs, 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); strcat(newbootargs, img_data.kcmdline);
}
if (*img_data.kcmdline_extra) { if (*img_data.kcmdline_extra) {
strcat(newbootargs, " "); if (*newbootargs) /* If there is something in newbootargs, a space is needed */
strcat(newbootargs, " ");
strcat(newbootargs, img_data.kcmdline_extra); strcat(newbootargs, img_data.kcmdline_extra);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment