[PATCH 1/1] common: avoid NULL dereference in console_devices_set

Simon Glass sjg at chromium.org
Sun Apr 2 04:39:57 CEST 2023


Hi Heinrich,

On Sat, 1 Apr 2023 at 23:14, Heinrich Schuchardt <
heinrich.schuchardt at canonical.com> wrote:
>
> If CONFIG_CONSOLE_MUX=y and CONFIG_SYS_CONSOLE_IS_IN_ENV=n, a NULL
> dereference occurs in console_devices_set().
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> ---
>  common/console.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/common/console.c b/common/console.c
> index e4301a4932..39e1ab0e24 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -243,6 +243,9 @@ int cd_count[MAX_FILES];
>
>  static void console_devices_set(int file, struct stdio_dev *dev)
>  {
> +       console_devices[file] = malloc(sizeof(struct stdio_dev *));
> +       if (!console_devices[file])
> +               return;

This is strange code and desperately needs a comment. As you say, it is
only called only when:

SYS_CONSOLE_IS_IN_ENV=n
CONSOLE_MUX=y

Please add some notes about this being allocated in iomux normally, but in
this case we just need a single device so it is allocated here...

>         console_devices[file][0] = dev;
>         cd_count[file] = 1;
>  }
> --
> 2.39.2
>

Regards,
SImon


More information about the U-Boot mailing list