U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mattijs Korpershoek <mkorpershoek@baylibre.com>
To: Nicolas Belin <nbelin@baylibre.com>,
	Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>,
	Safae Ouajih <souajih@baylibre.com>,
	Ahmad Draidi <ar2000jp@gmail.com>
Cc: u-boot@lists.denx.de, Nicolas Belin <nbelin@baylibre.com>
Subject: Re: [PATCH v2 3/3] boot: android: rework bootargs concatenation
Date: Wed, 18 Dec 2024 11:49:49 +0100	[thread overview]
Message-ID: <87pllpw9iq.fsf@baylibre.com> (raw)
In-Reply-To: <20241217-fix-bootargs-concatenation-v2-3-b2fd7cf4e130@baylibre.com>

Hi Nicolas,

Thank you for the patch.

On mar., déc. 17, 2024 at 14:29, Nicolas Belin <nbelin@baylibre.com> wrote:

> 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: Nicolas Belin <nbelin@baylibre.com>

Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

> ---
>  boot/image-android.c | 29 ++++++++++++++++-------------
>  1 file changed, 16 insertions(+), 13 deletions(-)
>
> diff --git a/boot/image-android.c b/boot/image-android.c
> index 362a5c7435a3a8bcf7b674b96e31069a91a892b5..61ac312db7ad9ba6c55727469dd4ded61824c67c 100644
> --- a/boot/image-android.c
> +++ b/boot/image-android.c
> @@ -287,37 +287,40 @@ 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) {
>  		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 (*newbootargs) /* If there is something in newbootargs, a space is needed */
> +			strcat(newbootargs, " ");
>  		strcat(newbootargs, img_data.kcmdline_extra);
>  	}
>  
>
> -- 
> 2.34.1

  reply	other threads:[~2024-12-18 10:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-17 13:29 [PATCH v2 0/3] boot: android: rework the bootargs concatenation Nicolas Belin
2024-12-17 13:29 ` [PATCH v2 1/3] boot: android: fix extra command line support Nicolas Belin
2024-12-17 13:29 ` [PATCH v2 2/3] boot: android: free newbootargs when done Nicolas Belin
2024-12-17 13:29 ` [PATCH v2 3/3] boot: android: rework bootargs concatenation Nicolas Belin
2024-12-18 10:49   ` Mattijs Korpershoek [this message]
2024-12-18 13:05 ` [PATCH v2 0/3] boot: android: rework the " Mattijs Korpershoek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pllpw9iq.fsf@baylibre.com \
    --to=mkorpershoek@baylibre.com \
    --cc=ar2000jp@gmail.com \
    --cc=nbelin@baylibre.com \
    --cc=sjg@chromium.org \
    --cc=souajih@baylibre.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox