diff options
author | Simon Glass <sjg@chromium.org> | 2018-06-12 00:04:56 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2018-06-18 14:43:14 -0400 |
commit | af880e247d502844e01219995cbdbee4b3e6d204 (patch) | |
tree | 64a372e1ba5a814387d03e25d311eabcdc269f98 /common | |
parent | c2e4e7e6316a1683be56618a5918732477742fbc (diff) | |
download | u-boot-af880e247d502844e01219995cbdbee4b3e6d204.tar.gz |
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>
Diffstat (limited to 'common')
-rw-r--r-- | common/console.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/common/console.c b/common/console.c index 2688af56e1..2ba33dc574 100644 --- a/common/console.c +++ b/common/console.c @@ -502,8 +502,10 @@ void putc(const char c) return; } #endif + if (!gd) + return; #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); #endif #ifdef CONFIG_SILENT_CONSOLE @@ -541,8 +543,10 @@ void puts(const char *s) return; } #endif + if (!gd) + return; #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)); #endif #ifdef CONFIG_SILENT_CONSOLE |