diff options
author | Heinrich Schuchardt <xypron.glpk@gmx.de> | 2019-04-26 18:39:00 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2019-05-05 08:48:50 -0400 |
commit | 6c74e94a6529625845557aa5fc2041f7355ba02a (patch) | |
tree | 3ee2fcf5eba59f4d75f642e96c8f7f7a11bebc36 /lib/display_options.c | |
parent | ed885e752f3fdf4d0015362be60c6f259582a15f (diff) | |
download | u-boot-6c74e94a6529625845557aa5fc2041f7355ba02a.tar.gz |
lib/display_options: avoid illegal memory access
display_options_get_banner_priv() overwrites bytes before the start of the
buffer if the buffer size is less then 3. This case occurs in the Sandbox
when executing the `ut_print` command.
Correctly handle small buffer sizes. Adjust the print unit test to catch
when bytes before the buffer are overwritten.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/display_options.c')
-rw-r--r-- | lib/display_options.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/display_options.c b/lib/display_options.c index af1802ef99..cff20f3755 100644 --- a/lib/display_options.c +++ b/lib/display_options.c @@ -23,7 +23,9 @@ char *display_options_get_banner_priv(bool newlines, const char *build_tag, build_tag); if (len > size - 3) len = size - 3; - strcpy(buf + len, "\n\n"); + if (len < 0) + len = 0; + snprintf(buf + len, size - len, "\n\n"); return buf; } |