* [PATCH 1/1] common: avoid NULL dereference in console_devices_set
@ 2023-04-01 10:14 Heinrich Schuchardt
2023-04-02 2:39 ` Simon Glass
0 siblings, 1 reply; 2+ messages in thread
From: Heinrich Schuchardt @ 2023-04-01 10:14 UTC (permalink / raw)
To: Tom Rini
Cc: Simon Glass, Pali Rohár, Rasmus Villemoes, Harald Seiler,
Stefan Roese, u-boot, Heinrich Schuchardt
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@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;
console_devices[file][0] = dev;
cd_count[file] = 1;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] common: avoid NULL dereference in console_devices_set
2023-04-01 10:14 [PATCH 1/1] common: avoid NULL dereference in console_devices_set Heinrich Schuchardt
@ 2023-04-02 2:39 ` Simon Glass
0 siblings, 0 replies; 2+ messages in thread
From: Simon Glass @ 2023-04-02 2:39 UTC (permalink / raw)
To: Heinrich Schuchardt
Cc: Tom Rini, Pali Rohár, Rasmus Villemoes, Harald Seiler,
Stefan Roese, U-Boot Mailing List
Hi Heinrich,
On Sat, 1 Apr 2023 at 23:14, Heinrich Schuchardt <
heinrich.schuchardt@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@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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-04-02 2:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-01 10:14 [PATCH 1/1] common: avoid NULL dereference in console_devices_set Heinrich Schuchardt
2023-04-02 2:39 ` Simon Glass
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).