public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Carlos O'Donell <carlos@redhat.com>
To: Florian Weimer <fweimer@redhat.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH 2/5] locale: Fix signed char bug in lr_getc
Date: Mon, 4 Jul 2022 15:54:13 -0400	[thread overview]
Message-ID: <5c1393d8-cc69-e77b-a674-c00460cbeece@redhat.com> (raw)
In-Reply-To: <619cade7e73dc33184bf4247b739d54cd9d7d8b3.1652994079.git.fweimer@redhat.com>

On 5/19/22 17:06, Florian Weimer via Libc-alpha wrote:
> The array lr->buf contains characters, which can be signed.  A 0xff
> byte in the input could be incorrectly reported as EOF.  More
> importantly, get_string in linereader.c converts a signed input byte
> to a Unicode code point using ADDWC ((uint32_t) ch), under the
> assumption that this decodes the ISO-8859-1 input encoding.  If char
> is signed, this does not give the correct result.  This means that
> ISO-8859-1 input files for localedef are not actually supported,
> contrary to the comment in get_string.  This is a happy accident because
> we can therefore change the file encoding to UTF-8 without impacting
> backwards compatibility.

LGTM.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>

> 
> While at it, remove the \32 check for MS-DOS end-of-file character (^Z).

OK. We don't need this, files should have the correct EOF.

> ---
>  locale/programs/linereader.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/locale/programs/linereader.h b/locale/programs/linereader.h
> index 0fb10ec833..653a71d2d1 100644
> --- a/locale/programs/linereader.h
> +++ b/locale/programs/linereader.h
> @@ -134,7 +134,7 @@ lr_getc (struct linereader *lr)
>  	return EOF;
>      }
>  
> -  return lr->buf[lr->idx] == '\32' ? EOF : lr->buf[lr->idx++];
> +  return lr->buf[lr->idx++] & 0xff;

OK. Agreed, this should not be sign extended. It's a byte in the buffer not EOF.
With the original MS-DOS checking it might have been *needed* to return -1.

>  }
>  
>  


-- 
Cheers,
Carlos.


  reply	other threads:[~2022-07-04 19:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-19 21:06 [PATCH 0/5] Assume UTF-8 encoding for localedef input files Florian Weimer
2022-05-19 21:06 ` [PATCH 1/5] locale: Turn ADDC and ADDS into functions in linereader.c Florian Weimer
2022-07-04 19:54   ` Carlos O'Donell
2022-05-19 21:06 ` [PATCH 2/5] locale: Fix signed char bug in lr_getc Florian Weimer
2022-07-04 19:54   ` Carlos O'Donell [this message]
2022-05-19 21:06 ` [PATCH 3/5] locale: Introduce translate_unicode_codepoint into linereader.c Florian Weimer
2022-07-04 19:54   ` Carlos O'Donell
2022-05-19 21:06 ` [PATCH 4/5] locale: localdef input files are now encoded in UTF-8 Florian Weimer
2022-07-04 19:54   ` Carlos O'Donell
2022-05-19 21:06 ` [PATCH 5/5] de_DE: Convert to UTF-8 Florian Weimer
2022-07-04 19:54   ` Carlos O'Donell
2022-07-05  9:27   ` Andreas Schwab
2022-07-05  9:55     ` Florian Weimer
2022-07-05 10:38       ` Andreas Schwab
2022-07-04 19:54 ` [PATCH 0/5] Assume UTF-8 encoding for localedef input files Carlos O'Donell

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=5c1393d8-cc69-e77b-a674-c00460cbeece@redhat.com \
    --to=carlos@redhat.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).