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

Implement preventing Sys::Hostname::hostname() from accepting arguments #17019

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

Implement preventing Sys::Hostname::hostname() from accepting arguments #17019

p5pRT opened this issue May 25, 2019 · 8 comments
Milestone

Comments

@p5pRT
Copy link

p5pRT commented May 25, 2019

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

Searchable as RT134137$

@p5pRT
Copy link
Author

p5pRT commented May 25, 2019

From @jkeenan

pod/perldeprecation.pod contains this entry for perl-5.32​:

#####
hostname() doesn't accept any arguments

The function
"hostname()" in the Sys​::Hostname module has always been
documented to be called with no arguments. Historically it
has not enforced this, and has actually accepted and
ignored any arguments. As a result, some users have got the
mistaken impression that an argument does something useful.
To avoid these bugs, the function is being made strict.
Passing arguments was deprecated in Perl 5.28, and will
become fatal in Perl 5.32.
#####

This entry was recorded in the following commit​:

#####
commit 0c9c439
Author​: Zefram <zefram@​fysh.org>
Date​: Wed Dec 6 16​:28​:18 2017 +0000

document hostname(@​args) deprecation

Passing arguments to Sys​::Hostname​::hostname() is already
deprecated. Note the deprecation's agreed removal version
of Perl 5.32. Also document it in perldeprecation.pod.
#####

Make it so.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented May 25, 2019

From @jkeenan

Summary of my perl5 (revision 5 version 31 subversion 0) configuration​:
  Commit id​: 58f4626
  Platform​:
  osname=linux
  osvers=4.15.0-50-generic
  archname=x86_64-linux
  uname='linux zareason 4.15.0-50-generic #54-ubuntu smp mon may 6 18​:46​:08 utc 2019 x86_64 x86_64 x86_64 gnulinux '
  config_args='-des -Dusedevel -Dusemymalloc=y'
  hint=recommended
  useposix=true
  d_sigaction=define
  useithreads=undef
  usemultiplicity=undef
  use64bitint=define
  use64bitall=define
  uselongdouble=undef
  usemymalloc=y
  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.4.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 /lib64 /usr/lib64
  libs=-lpthread -lnsl -lgdbm -ldb -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'

Characteristics of this binary (from libperl)​:
  Compile-time options​:
  HAS_TIMES
  MYMALLOC
  PERLIO_LAYERS
  PERL_COPY_ON_WRITE
  PERL_DONT_CREATE_GVSV
  PERL_MALLOC_WRAP
  PERL_OP_PARENT
  PERL_PRESERVE_IVUV
  PERL_USE_DEVEL
  USE_64_BIT_ALL
  USE_64_BIT_INT
  USE_LARGE_FILES
  USE_LOCALE
  USE_LOCALE_COLLATE
  USE_LOCALE_CTYPE
  USE_LOCALE_NUMERIC
  USE_LOCALE_TIME
  USE_PERLIO
  USE_PERL_ATOF
  Built under linux
  Compiled at May 22 2019 14​:58​:04
  %ENV​:
  PERL2DIR="/home/jkeenan/gitwork/perl2"
  PERLBREW_HOME="/home/jkeenan/.perlbrew"
  PERLBREW_MANPATH="/home/jkeenan/perl5/perlbrew/perls/perl-5.28.0/man"
  PERLBREW_PATH="/home/jkeenan/perl5/perlbrew/bin​:/home/jkeenan/perl5/perlbrew/perls/perl-5.28.0/bin"
  PERLBREW_PERL="perl-5.28.0"
  PERLBREW_ROOT="/home/jkeenan/perl5/perlbrew"
  PERLBREW_SHELLRC_VERSION="0.84"
  PERLBREW_VERSION="0.84"
  PERL_WORKDIR="/home/jkeenan/gitwork/perl"
  @​INC​:
  lib
  /usr/local/lib/perl5/site_perl/5.31.0/x86_64-linux
  /usr/local/lib/perl5/site_perl/5.31.0
  /usr/local/lib/perl5/5.31.0/x86_64-linux
  /usr/local/lib/perl5/5.31.0

@p5pRT
Copy link
Author

p5pRT commented May 25, 2019

From @jkeenan

On Sat, 25 May 2019 01​:56​:12 GMT, jkeenan@​pobox.com wrote​:

pod/perldeprecation.pod contains this entry for perl-5.32​:

#####
hostname() doesn't accept any arguments

The function
"hostname()" in the Sys​::Hostname module has always been
documented to be called with no arguments. Historically it
has not enforced this, and has actually accepted and
ignored any arguments. As a result, some users have got the
mistaken impression that an argument does something useful.
To avoid these bugs, the function is being made strict.
Passing arguments was deprecated in Perl 5.28, and will
become fatal in Perl 5.32.
#####

This entry was recorded in the following commit​:

#####
commit 0c9c439
Author​: Zefram <zefram@​fysh.org>
Date​: Wed Dec 6 16​:28​:18 2017 +0000

document hostname(@​args) deprecation

Passing arguments to Sys​::Hostname​::hostname() is already
deprecated. Note the deprecation's agreed removal version
of Perl 5.32. Also document it in perldeprecation.pod.
#####

Make it so.

Thank you very much.
Jim Keenan

Please review patch attached (or smoke-me/jkeenan/rt-134137-hostname branch).

Thank you very much.
--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented May 25, 2019

From @jkeenan

0001-Prevent-hostname-from-accepting-arguments.patch
From 811314492d0ed875a2622bb1f030f711ac5399bb Mon Sep 17 00:00:00 2001
From: James E Keenan <jkeenan@cpan.org>
Date: Fri, 24 May 2019 22:37:40 -0400
Subject: [PATCH] Prevent hostname() from accepting arguments

Increment $VERSION.

For: RT 134137
---
 ext/Sys-Hostname/Hostname.pm  |  4 ++--
 ext/Sys-Hostname/t/Hostname.t | 17 +++++------------
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/ext/Sys-Hostname/Hostname.pm b/ext/Sys-Hostname/Hostname.pm
index 8b5dde1445..ddf98b8d18 100644
--- a/ext/Sys-Hostname/Hostname.pm
+++ b/ext/Sys-Hostname/Hostname.pm
@@ -16,7 +16,7 @@ use warnings ();
 our $host;
 
 BEGIN {
-    $VERSION = '1.22';
+    $VERSION = '1.23';
     {
 	local $SIG{__DIE__};
 	eval {
@@ -29,7 +29,7 @@ BEGIN {
 
 
 sub hostname {
-  @_ and warnings::warnif("deprecated", "hostname() doesn't accept any arguments. This will become fatal in Perl 5.32");
+  @_ and die("hostname() no longer accepts arguments");
 
   # method 1 - we already know it
   return $host if defined $host;
diff --git a/ext/Sys-Hostname/t/Hostname.t b/ext/Sys-Hostname/t/Hostname.t
index a8c259d7c9..9aaf464339 100644
--- a/ext/Sys-Hostname/t/Hostname.t
+++ b/ext/Sys-Hostname/t/Hostname.t
@@ -10,7 +10,7 @@ BEGIN {
 
 use Sys::Hostname;
 
-use Test::More tests => 4;
+use Test::More tests => 2;
 
 SKIP:
 {
@@ -23,15 +23,8 @@ SKIP:
 }
 
 {
-    use warnings;
-    my $warn;
-    local $SIG{__WARN__} = sub { $warn = "@_" };
-    eval { hostname("dummy") };
-    ok($warn, "warns with an argument");
-    like($warn, qr/hostname\(\) doesn't accept any arguments/,
-         "appropriate message");
-    no warnings "deprecated";
-    undef $warn;
-    eval { hostname("dummy") };
-    is($warn, undef, "no warning when disabled");
+    local $@;
+    eval { hostname("dummy"); };
+    like($@, qr/hostname\(\) no longer accepts arguments/,
+        "hostname no longer accepts arguments");
 }
-- 
2.17.1

@p5pRT
Copy link
Author

p5pRT commented May 25, 2019

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

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2019

From @tonycoz

On Fri, 24 May 2019 19​:48​:35 -0700, jkeenan wrote​:

On Sat, 25 May 2019 01​:56​:12 GMT, jkeenan@​pobox.com wrote​:

pod/perldeprecation.pod contains this entry for perl-5.32​:

#####
hostname() doesn't accept any arguments

The function
"hostname()" in the Sys​::Hostname module has always been
documented to be called with no arguments. Historically it
has not enforced this, and has actually accepted and
ignored any arguments. As a result, some users have got the
mistaken impression that an argument does something useful.
To avoid these bugs, the function is being made strict.
Passing arguments was deprecated in Perl 5.28, and will
become fatal in Perl 5.32.
#####

This entry was recorded in the following commit​:

#####
commit 0c9c439
Author​: Zefram <zefram@​fysh.org>
Date​: Wed Dec 6 16​:28​:18 2017 +0000

document hostname(@​args) deprecation

Passing arguments to Sys​::Hostname​::hostname() is already
deprecated. Note the deprecation's agreed removal version
of Perl 5.32. Also document it in perldeprecation.pod.
#####

Make it so.

Thank you very much.
Jim Keenan

Please review patch attached (or smoke-me/jkeenan/rt-134137-hostname
branch).

Thank you very much.

- @​_ and warnings​::warnif("deprecated", "hostname() doesn't accept any arguments. This will become fatal in Perl 5.32");
+ @​_ and die("hostname() no longer accepts arguments");

Two issues​:

- this should probably use croak() instead of die() so the error is produced at the caller

- Richard's point about the error message in

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

which didn't make it to the ticket.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jun 5, 2019

From @jkeenan

On Tue, 04 Jun 2019 23​:53​:53 GMT, tonyc wrote​:

On Fri, 24 May 2019 19​:48​:35 -0700, jkeenan wrote​:

On Sat, 25 May 2019 01​:56​:12 GMT, jkeenan@​pobox.com wrote​:

pod/perldeprecation.pod contains this entry for perl-5.32​:

#####
hostname() doesn't accept any arguments

The function
"hostname()" in the Sys​::Hostname module has always been
documented to be called with no arguments. Historically it
has not enforced this, and has actually accepted and
ignored any arguments. As a result, some users have got the
mistaken impression that an argument does something useful.
To avoid these bugs, the function is being made strict.
Passing arguments was deprecated in Perl 5.28, and will
become fatal in Perl 5.32.
#####

This entry was recorded in the following commit​:

#####
commit 0c9c439
Author​: Zefram <zefram@​fysh.org>
Date​: Wed Dec 6 16​:28​:18 2017 +0000

document hostname(@​args) deprecation

Passing arguments to Sys​::Hostname​::hostname() is already
deprecated. Note the deprecation's agreed removal version
of Perl 5.32. Also document it in perldeprecation.pod.
#####

Make it so.

Thank you very much.
Jim Keenan

Please review patch attached (or smoke-me/jkeenan/rt-134137-hostname
branch).

Thank you very much.

- @​_ and warnings​::warnif("deprecated", "hostname() doesn't accept any
arguments. This will become fatal in Perl 5.32");
+ @​_ and die("hostname() no longer accepts arguments");

Two issues​:

- this should probably use croak() instead of die() so the error is
produced at the caller

- Richard's point about the error message in

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

which didn't make it to the ticket.

Tony

Thanks for the code review. Incorporated suggestions and merged to blead in commit 82b5311.

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

@p5pRT
Copy link
Author

p5pRT commented Jun 5, 2019

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

@p5pRT p5pRT closed this as completed Jun 5, 2019
@toddr toddr added this to the 5.32.0 milestone Oct 25, 2019
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

2 participants