1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-09-01 00:32:04 +02:00

console: Fix handling of NULL global_data

Both putc() and puts() can be called before global_data is set up. Some of
the code paths don't handle this correctly. Add an explicit test before
any member is accessed.

Reported-by: Coverity (CID: 169030)
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
This commit is contained in:
Simon Glass
2018-06-12 00:04:56 -06:00
committed by Tom Rini
parent c2e4e7e631
commit af880e247d

View File

@@ -502,8 +502,10 @@ void putc(const char c)
return; return;
} }
#endif #endif
if (!gd)
return;
#ifdef CONFIG_CONSOLE_RECORD #ifdef CONFIG_CONSOLE_RECORD
if (gd && (gd->flags & GD_FLG_RECORD) && gd->console_out.start) if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
membuff_putbyte(&gd->console_out, c); membuff_putbyte(&gd->console_out, c);
#endif #endif
#ifdef CONFIG_SILENT_CONSOLE #ifdef CONFIG_SILENT_CONSOLE
@@ -541,8 +543,10 @@ void puts(const char *s)
return; return;
} }
#endif #endif
if (!gd)
return;
#ifdef CONFIG_CONSOLE_RECORD #ifdef CONFIG_CONSOLE_RECORD
if (gd && (gd->flags & GD_FLG_RECORD) && gd->console_out.start) if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
membuff_put(&gd->console_out, s, strlen(s)); membuff_put(&gd->console_out, s, strlen(s));
#endif #endif
#ifdef CONFIG_SILENT_CONSOLE #ifdef CONFIG_SILENT_CONSOLE