All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 07/17] lib: vsprintf: correct printing of Unicode strings
Date: Sat, 1 Sep 2018 11:31:02 +0200	[thread overview]
Message-ID: <635aac61-f6fe-c130-9d26-797896807f15@suse.de> (raw)
In-Reply-To: <20180831193139.2517-8-xypron.glpk@gmx.de>



On 31.08.18 21:31, Heinrich Schuchardt wrote:
> The width and precision of the printf() function refer to the number of
> characters not to the number of bytes printed.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> v2:
> 	use library function utf16_utf8_strncpy() for string16()
> ---
>  lib/vsprintf.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 5abf734750..4213441fbf 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -280,18 +280,13 @@ static char *string16(char *buf, char *end, u16 *s, int field_width,
>  		int precision, int flags)
>  {
>  	u16 *str = s ? s : L"<NULL>";
> -	int utf16_len = u16_strnlen(str, precision);
> -	u8 utf8[utf16_len * MAX_UTF8_PER_UTF16];
> -	int utf8_len, i;
> -
> -	utf8_len = utf16_to_utf8(utf8, str, utf16_len) - utf8;
> +	ssize_t len = utf16_strnlen(str, precision);
>  
>  	if (!(flags & LEFT))
> -		while (utf8_len < field_width--)
> +		for (; len < field_width; --field_width)
>  			ADDCH(buf, ' ');
> -	for (i = 0; i < utf8_len; ++i)
> -		ADDCH(buf, utf8[i]);
> -	while (utf8_len < field_width--)
> +	utf16_utf8_strncpy(&buf, str, len);
> +	for (; len < field_width; --field_width)
>  		ADDCH(buf, ' ');
>  	return buf;

Both the string() and string16() functions seem to completely ignore the
"end" variable. Doesn't that mean we're potentially running over the end
of a buffer with snprintf()?

I think the patch as is is fine, because string() has the same problem
and the previous version didn't bother either. But in the long run, we
should probably fix the end checks.


Alex

  reply	other threads:[~2018-09-01  9:31 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-31 19:31 [U-Boot] [PATCH v2 00/17][RESENT] efi_loader: EFI_UNICODE_COLLATION_PROTOCOL Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 01/17] vsprintf.c: use #if CONFIG_IS_ENABLED(EFI_LOADER) Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 02/17] test: print_ut.c " Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 03/17] lib: build charset.o only if needed Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 04/17] efi_loader: rename utf16_strlen, utf16_strnlen Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 05/17] lib: charset: utility functions for Unicode Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 06/17] test: unit tests for Unicode functions Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 07/17] lib: vsprintf: correct printing of Unicode strings Heinrich Schuchardt
2018-09-01  9:31   ` Alexander Graf [this message]
2018-08-31 19:31 ` [U-Boot] [PATCH v2 08/17] test: test printing Unicode Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 09/17] efi_loader: remove limit on variable length Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 10/17] efi_loader: don't use unlimited stack as buffer Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 11/17] efi_loader: buffer size for load options Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 12/17] lib: charset: remove obsolete functions Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 13/17] efi_loader: capitalization table Heinrich Schuchardt
2018-09-01  9:43   ` Alexander Graf
2018-09-01  9:50     ` Alexander Graf
2018-08-31 19:31 ` [U-Boot] [PATCH 14/17] lib: charset: upper/lower case conversion Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 15/17] test: tests for utf_to_lower() utf_to_upper() Heinrich Schuchardt
2018-09-01  9:47   ` Alexander Graf
2018-08-31 19:31 ` [U-Boot] [PATCH v2 16/17] efi_loader: EFI_UNICODE_COLLATION_PROTOCOL Heinrich Schuchardt
2018-08-31 19:31 ` [U-Boot] [PATCH v2 17/17] efi_selftest: EFI_UNICODE_COLLATION_PROTOCOL Heinrich Schuchardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=635aac61-f6fe-c130-9d26-797896807f15@suse.de \
    --to=agraf@suse.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.