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

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>
This commit is contained in:
Heinrich Schuchardt
2019-04-26 18:39:00 +02:00
committed by Tom Rini
parent ed885e752f
commit 6c74e94a65
2 changed files with 13 additions and 7 deletions

View File

@@ -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;
}