]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
lib: vsprintf: avoid overflow printing UTF16 strings
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Sun, 10 Feb 2019 10:11:26 +0000 (11:11 +0100)
committerAlexander Graf <agraf@suse.de>
Wed, 13 Feb 2019 08:40:06 +0000 (09:40 +0100)
We have to ensure while printing UTF16 strings that we do not exceed the
end of the print buffer.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
lib/vsprintf.c

index 4213441fbf773408b5519e48eab0141ef50ae358..de5db1aa5c7f4eef2d8a6aebecef23c05fb43fe5 100644 (file)
@@ -279,13 +279,17 @@ static char *string(char *buf, char *end, char *s, int field_width,
 static char *string16(char *buf, char *end, u16 *s, int field_width,
                int precision, int flags)
 {
-       u16 *str = s ? s : L"<NULL>";
-       ssize_t len = utf16_strnlen(str, precision);
+       const u16 *str = s ? s : L"<NULL>";
+       ssize_t i, len = utf16_strnlen(str, precision);
 
        if (!(flags & LEFT))
                for (; len < field_width; --field_width)
                        ADDCH(buf, ' ');
-       utf16_utf8_strncpy(&buf, str, len);
+       for (i = 0; i < len && buf + utf16_utf8_strnlen(str, 1) <= end; ++i) {
+               s32 s = utf16_get(&str);
+
+               utf8_put(s, &buf);
+       }
        for (; len < field_width; --field_width)
                ADDCH(buf, ' ');
        return buf;