All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: u-boot@lists.denx.de
Subject: [PATCH 2/4] efi_loader: illegal free in EFI_LOAD_FILE2_PROTOCOL
Date: Sun, 4 Oct 2020 08:16:03 +0300	[thread overview]
Message-ID: <20201004051603.GB27264@Iliass-MBP> (raw)
In-Reply-To: <20201003115716.38058-3-xypron.glpk@gmx.de>

On Sat, Oct 03, 2020 at 01:57:14PM +0200, Heinrich Schuchardt wrote:
> strsep() changes the address that its first argument points to.
> We cannot use the changed address as argument of free().
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  lib/efi_loader/efi_load_initrd.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c
> index ff69e6eb79..d517d686c3 100644
> --- a/lib/efi_loader/efi_load_initrd.c
> +++ b/lib/efi_loader/efi_load_initrd.c
> @@ -98,19 +98,20 @@ efi_load_file2_initrd(struct efi_load_file_protocol *this,
>  		      struct efi_device_path *file_path, bool boot_policy,
>  		      efi_uintn_t *buffer_size, void *buffer)
>  {
> -	const char *filespec = CONFIG_EFI_INITRD_FILESPEC;
> +	char *filespec;
>  	efi_status_t status = EFI_NOT_FOUND;
>  	loff_t file_sz = 0, read_sz = 0;
>  	char *dev, *part, *file;
> -	char *s;
> +	char *pos;
>  	int ret;
> 
>  	EFI_ENTRY("%p, %p, %d, %p, %p", this, file_path, boot_policy,
>  		  buffer_size, buffer);
> 
> -	s = strdup(filespec);
> -	if (!s)
> +	filespec = strdup(CONFIG_EFI_INITRD_FILESPEC);
> +	if (!filespec)
>  		goto out;
> +	pos = filespec;
> 
>  	if (!this || this != &efi_lf2_protocol ||
>  	    !buffer_size) {
> @@ -136,13 +137,13 @@ efi_load_file2_initrd(struct efi_load_file_protocol *this,
>  	 * * a device and partition identifier, e.g. "0:1"
>  	 * * a file path on the block device, e.g. "/boot/initrd.cpio.gz"
>  	 */
> -	dev = strsep(&s, " ");
> +	dev = strsep(&pos, " ");
>  	if (!dev)
>  		goto out;
> -	part = strsep(&s, " ");
> +	part = strsep(&pos, " ");
>  	if (!part)
>  		goto out;
> -	file = strsep(&s, " ");
> +	file = strsep(&pos, " ");
>  	if (!file)
>  		goto out;
> 
> @@ -170,7 +171,7 @@ efi_load_file2_initrd(struct efi_load_file_protocol *this,
>  	}
> 
>  out:
> -	free(s);
> +	free(filespec);
>  	return EFI_EXIT(status);
>  }
> 
> --
> 2.28.0
> 

Not changing the variable names would make this an one liner to read.
The changes do make sense though so 

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

  reply	other threads:[~2020-10-04  5:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-03 11:57 [PATCH 0/4] efi_loader: fix EFI_LOAD_FILE2_PROTOCOL Heinrich Schuchardt
2020-10-03 11:57 ` [PATCH 1/4] efi_loader: description EFI_LOAD_FILE2_PROTOCOL Heinrich Schuchardt
2020-10-04  5:14   ` Ilias Apalodimas
2020-10-03 11:57 ` [PATCH 2/4] efi_loader: illegal free in EFI_LOAD_FILE2_PROTOCOL Heinrich Schuchardt
2020-10-04  5:16   ` Ilias Apalodimas [this message]
2020-10-03 11:57 ` [PATCH 3/4] efi_selftest: enable printing hexadecimal numbers Heinrich Schuchardt
2020-10-03 11:57 ` [PATCH 4/4] efi_selftest: print CRC32 of initrd as hexadecimal Heinrich Schuchardt
2020-10-04  5:16   ` Ilias Apalodimas

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=20201004051603.GB27264@Iliass-MBP \
    --to=ilias.apalodimas@linaro.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.