Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] locale.c: cast to char before comparing with a char constant #16989

Closed
p5pRT opened this issue May 4, 2019 · 8 comments
Closed

[PATCH] locale.c: cast to char before comparing with a char constant #16989

p5pRT opened this issue May 4, 2019 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented May 4, 2019

Migrated from rt.perl.org#134080 (status was 'pending release')

Searchable as RT134080$

@p5pRT
Copy link
Author

p5pRT commented May 4, 2019

From jerome.duval@gmail.com

From​: jerome.duval@​gmail.com
MIME-Version​: 1.0
To​: perlbug@​perl.org
Content-Type​: multipart/mixed; boundary="------------1.41.perlbug"
Subject​: [PATCH] locale.c​: cast to char before comparing with a char constant
Reply-To​: jerome.duval@​gmail.com
Message-Id​: <5.29.10_15312_1556965377@​korli-UX430UAR>

This is a multi-part message in MIME format.
--------------1.41.perlbug
Content-Type​: text/plain; format=fixed
Content-Transfer-Encoding​: 8bit

This is a bug report for perl from jerome.duval@​gmail.com,
generated with the help of perlbug 1.41 running under perl 5.29.10.


locale.c​: the corruption check for the utf8ness_cache should cast
to char before comparing with a char.
on gcc 2.95 without the cast, the check always fails.



Flags​:
  category=core
  severity=low
  Type=Patch
  PatchStatus=HasPatch


Site configuration information for perl 5.29.10​:

Configured by korli at Sat May 4 12​:06​:04 CEST 2019.

Summary of my perl5 (revision 5 version 29 subversion 10) configuration​:
  Local Commit​: 5433b288b31a6509217b8c047cac1150f6dcabeb
  Ancestor​: 2ede670
  Platform​:
  osname=linux
  osvers=4.15.0-48-generic
  archname=x86_64-linux
  uname='linux korli-ux430uar 4.15.0-48-generic #51-ubuntu smp wed
apr 3 08​:28​:49 utc 2019 x86_64 x86_64 x86_64 gnulinux '
  config_args='-des -Dusedevel'
  hint=recommended
  useposix=true
  d_sigaction=define
  useithreads=undef
  usemultiplicity=undef
  use64bitint=define
  use64bitall=define
  uselongdouble=undef
  usemymalloc=n
  default_inc_excludes_dot=define
  bincompat5005=undef
  Compiler​:
  cc='cc'
  ccflags ='-fwrapv -fno-strict-aliasing -pipe
-fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64'
  optimize='-O2'
  cppflags='-fwrapv -fno-strict-aliasing -pipe
-fstack-protector-strong -I/usr/local/include'
  ccversion=''
  gccversion='7.3.0'
  gccosandvers=''
  intsize=4
  longsize=8
  ptrsize=8
  doublesize=8
  byteorder=12345678
  doublekind=3
  d_longlong=define
  longlongsize=8
  d_longdbl=define
  longdblsize=16
  longdblkind=3
  ivtype='long'
  ivsize=8
  nvtype='double'
  nvsize=8
  Off_t='off_t'
  lseeksize=8
  alignbytes=8
  prototype=define
  Linker and Libraries​:
  ld='cc'
  ldflags =' -fstack-protector-strong -L/usr/local/lib'
  libpth=/usr/local/lib
/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
/usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu
/lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
  libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
  perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
  libc=libc-2.27.so
  so=so
  useshrplib=false
  libperl=libperl.a
  gnulibc_version='2.27'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs
  dlext=so
  d_dlsymun=undef
  ccdlflags='-Wl,-E'
  cccdlflags='-fPIC'
  lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'

Locally applied patches​:
  5433b288b31a6509217b8c047cac1150f6dcabeb


@​INC for perl 5.29.10​:
  lib
  /usr/local/lib/perl5/site_perl/5.29.10/x86_64-linux
  /usr/local/lib/perl5/site_perl/5.29.10
  /usr/local/lib/perl5/5.29.10/x86_64-linux
  /usr/local/lib/perl5/5.29.10


Environment for perl 5.29.10​:
  HOME=/home/korli
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LC_ADDRESS=fr_FR.UTF-8
  LC_IDENTIFICATION=fr_FR.UTF-8
  LC_MEASUREMENT=fr_FR.UTF-8
  LC_MONETARY=fr_FR.UTF-8
  LC_NAME=fr_FR.UTF-8
  LC_NUMERIC=fr_FR.UTF-8
  LC_PAPER=fr_FR.UTF-8
  LC_TELEPHONE=fr_FR.UTF-8
  LC_TIME=fr_FR.UTF-8
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/local/sbin​:/usr/local/bin​:/usr/sbin​:/usr/bin​:/sbin​:/bin​:/usr/games​:/usr/local/games​:/snap/bin
  PERL_BADLANG (unset)
  SHELL=/bin/bash

--------------1.41.perlbug
Content-Type​: text/x-patch;
name="0001-locale.c-cast-to-char-before-comparing-with-a-char-c.patch"
Content-Transfer-Encoding​: 8bit
Content-Disposition​: attachment;
filename="0001-locale.c-cast-to-char-before-comparing-with-a-char-c.patch"

From 5433b288b31a6509217b8c047cac1150f6dcabeb Mon Sep 17 00​:00​:00 2001
From​: Jerome Duval <jerome.duval@​gmail.com>
Date​: Thu, 25 Apr 2019 23​:19​:43 +0200
Subject​: [PATCH] locale.c​: cast to char before comparing with a char constant.

exposed by gcc 2.95.


locale.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Inline Patch
diff --git a/locale.c b/locale.c
index 87e11d609d..756bd44334 100644
--- a/locale.c
+++ b/locale.c
@@ -5052,7 +5052,7 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category)
         Copy(delimited, utf8ness_cache, input_name_len_with_overhead
- 1, char);
         utf8ness_cache[input_name_len_with_overhead - 1] = is_utf8 + '0';

-        if ((PL_locale_utf8ness[strlen(PL_locale_utf8ness)-1]
+        if ((char)(PL_locale_utf8ness[strlen(PL_locale_utf8ness)-1]
                                                 & (PERL_UINTMAX_T) ~1) != '0')
         {
             Perl_croak(aTHX_
-- 
2.17.1

--------------1.41.perlbug--

@p5pRT
Copy link
Author

p5pRT commented May 5, 2019

From @jkeenan

On Sat, 04 May 2019 11​:00​:46 GMT, jerome.duval@​gmail.com wrote​:

From​: jerome.duval@​gmail.com
MIME-Version​: 1.0
To​: perlbug@​perl.org
Content-Type​: multipart/mixed; boundary="------------1.41.perlbug"
Subject​: [PATCH] locale.c​: cast to char before comparing with a char
constant
Reply-To​: jerome.duval@​gmail.com
Message-Id​: <5.29.10_15312_1556965377@​korli-UX430UAR>

This is a multi-part message in MIME format.
--------------1.41.perlbug
Content-Type​: text/plain; format=fixed
Content-Transfer-Encoding​: 8bit

This is a bug report for perl from jerome.duval@​gmail.com,
generated with the help of perlbug 1.41 running under perl 5.29.10.

-----------------------------------------------------------------
locale.c​: the corruption check for the utf8ness_cache should cast
to char before comparing with a char.
on gcc 2.95 without the cast, the check always fails.

1. Can you provide (as an attachment) the part of the 'make' output where this failure appears?

2. Can you re-send your patch as an attachment (rather than inline)? (That is easier for us to apply for testing in a branch.)

3. Does anyone have an explanation as to why this failure does not appear with C compilers released since 1999?

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented May 5, 2019

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented May 6, 2019

From jerome.duval@gmail.com

Am Sun, 05 May 2019 05​:38​:06 -0700, jkeenan schrieb​:

1. Can you provide (as an attachment) the part of the 'make' output
where this failure appears?

The build doesn't fail, the code produced does. The corruption check fails, it means it doesn't compare correctly the '0' character whereas the value is correct.
For reference here is a screenshot of the failure​: https://user-images.githubusercontent.com/16057090/56577273-e584de00-65ca-11e9-95fa-b68f3d37149c.png
I can attach the picture when desired.
Original bug report​: haikuports/haikuports#3789
The failure doesn't happen with the C locale, as the corruption check isn't triggered then.

2. Can you re-send your patch as an attachment (rather than inline)?
(That is easier for us to apply for testing in a branch.)

Attached.

3. Does anyone have an explanation as to why this failure does not
appear with C compilers released since 1999?

At least the impacted code was introduced since 5.26. Maybe it wasn't
tested on an older compiler.

@p5pRT
Copy link
Author

p5pRT commented May 6, 2019

From jerome.duval@gmail.com

0001-locale.c-cast-to-char-before-comparing-with-a-char-c.patch
From 5433b288b31a6509217b8c047cac1150f6dcabeb Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Thu, 25 Apr 2019 23:19:43 +0200
Subject: [PATCH] locale.c: cast to char before comparing with a char constant.

exposed by gcc 2.95.
---
 locale.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/locale.c b/locale.c
index 87e11d609d..756bd44334 100644
--- a/locale.c
+++ b/locale.c
@@ -5052,7 +5052,7 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category)
         Copy(delimited, utf8ness_cache, input_name_len_with_overhead - 1, char);
         utf8ness_cache[input_name_len_with_overhead - 1] = is_utf8 + '0';
 
-        if ((PL_locale_utf8ness[strlen(PL_locale_utf8ness)-1]
+        if ((char)(PL_locale_utf8ness[strlen(PL_locale_utf8ness)-1]
                                                 & (PERL_UINTMAX_T) ~1) != '0')
         {
             Perl_croak(aTHX_
-- 
2.17.1

@p5pRT
Copy link
Author

p5pRT commented May 16, 2019

From @tonycoz

For anyone following along via RT this has had further discussion on the list​:

https://www.nntp.perl.org/group/perl.perl5.porters/2019/05/msg254741.html

that hasn't made it to the ticket so far, due to the perl.org maintenance.

This includes a new patch.

This hasn't been patched in blead due to the release freeze.

Tony

@p5pRT
Copy link
Author

p5pRT commented May 25, 2019

From @khwilliamson

Fixed by

commit 72299e0
Author​: Jerome Duval <jerome.duval@​gmail.com>
Date​: Thu Apr 25 23​:19​:43 2019 +0200

* locale.c​: remove unnecessary cast
 
  This was failing in gcc 2.95. The original commit added a cast, but we
  figured out that removing this other one that really served no purpose
  causes this compiler to work.

--
Karl Williamson

@p5pRT
Copy link
Author

p5pRT commented May 25, 2019

@khwilliamson - Status changed from 'open' to 'pending release'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant