| Summary: | If no PATH is defined when calling Sys::Hostname::hostname, the function will fail due to exit values of the eval-uated code segments | ||||||
|---|---|---|---|---|---|---|---|
| Product: | Base System | Reporter: | pckizer <pckizer> | ||||
| Component: | bin | Assignee: | Mark Murray <markm> | ||||
| Status: | Closed FIXED | ||||||
| Severity: | Affects Only Me | ||||||
| Priority: | Normal | ||||||
| Version: | 3.2-STABLE | ||||||
| Hardware: | Any | ||||||
| OS: | Any | ||||||
| Attachments: |
|
||||||
Responsible Changed From-To: freebsd-bugs->sheldonh Sorry, I asked Mark for permission to MFC and then forgot to. I'll do it now. What you should be doing in your program is the following:
env PATH= /usr/bin/perl -e '
$ENV{PATH} = "/bin:/usr/bin"
unless $ENV{PATH};
use Sys::Hostname;
print Sys::Hostname::hostname(),"\n";
'
The cause of the problem is that the PATH is not set and setting it deep
down in some library is not the intended use of setting environment
variables. sendmail removes PATH from the environment for a reason
(security)
You agree that we close the PR?
Nick
> --- /tmp/perl5.005_03/lib/Sys/Hostname.pm Thu Sep 2 18:13:51 1999
> +++ Hostname.pm-orig Thu Sep 2 18:27:32 1999
> @@ -95,4 +95,7 @@
> || eval {
> + $pathstack = $ENV{'PATH'};
> + $ENV{'PATH'} = "/bin:/usr/bin";
> local $SIG{__DIE__};
> $host = `(hostname) 2>/dev/null`; # bsdish
> + $ENV{'PATH'} = $pathstack;
> }
> @@ -101,4 +104,7 @@
> || eval {
> + $pathstack = $ENV{'PATH'};
> + $ENV{'PATH'} = "/bin:/usr/bin";
> local $SIG{__DIE__};
> $host = `uname -n 2>/dev/null`; ## sysVish
> + $ENV{'PATH'} = $pathstack;
> }
>
> The problem this causes is that the eval-ed blocks are guarenteed to be
> taken as having failed as they will exit with the undef from the $ENV{'PATH'}
> variable assignment in the case where there is no PATH defined prior to the
> function call (such as, in my case, an automated invocation from sendmail),
>
>
> >How-To-Repeat:
>
> % /usr/bin/perl -e 'use Sys::Hostname; print Sys::Hostname::hostname(),"\n";'
> chariot.tamu.edu
>
> % env PATH= /usr/bin/perl -e 'use Sys::Hostname; print Sys::Hostname::hostname(),"\n";'
> Cannot get host name of local machine at -e line 1
>
>
> >Fix:
>
> The code blocks need to exit with a return value based on the success of
> the hostname determination. My quick fix was the following:
>
> --- Hostname.pm-orig Thu Sep 2 18:27:32 1999
> +++ Hostname.pm Thu Sep 2 18:33:13 1999
> @@ -100,2 +100,3 @@
> $ENV{'PATH'} = $pathstack;
> + $host;
> }
> @@ -109,2 +110,3 @@
> $ENV{'PATH'} = $pathstack;
> + $host;
> }
>
>
> >Release-Note:
> >Audit-Trail:
> >Unformatted:
>
>
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-bugs" in the body of the message
>
>
--
ISIS/STA, T.P.270, Joint Research Centre, 21020 Ispra, Italy
On Fri, 03 Sep 1999 09:29:48 +0200, Nick Hibma wrote:
> You agree that we close the PR?
No. This is a real problem. See rev 1.2 of Hostname.pm .
I'm just waiting for permission from Jordan to MFC Mark's change.
Ciao,
Sheldon.
State Changed From-To: open->closed Aaaiieee! This was MFC'd ages ago in rev 1.1.1.1.2.1 of Hostname.pm, which made it into 3.3-RELEASE. Sheldon Hearn <sheldonh@uunet.co.za> wrote: >No. This is a real problem. See rev 1.2 of Hostname.pm . >I'm just waiting for permission from Jordan to MFC Mark's change. OK, I just took a system to the latest 3.4-STABLE before I start my 4.0 changes this month, and found that this has not been put in, but the PR has been closed. References: PR: <http://www.FreeBSD.org/cgi/query-pr.cgi?pr=bin%2F13550> Versions with the problem: <http://www.FreeBSD.org/cgi/cvsweb.cgi/src/contrib/perl5/lib/Sys/Hostname.pm?rev=1.1.1.1.2.1> <http://www.FreeBSD.org/cgi/cvsweb.cgi/src/contrib/perl5/lib/Sys/Hostname.pm?rev=1.2> % export CVSROOT=:pserver:anoncvs@anoncvs.FreeBSD.org:/home/ncvs % cvs login % cvs co -rRELENG_4 src/contrib/perl5/lib/Sys/ cvs server: Updating src/contrib/perl5/lib/Sys U src/contrib/perl5/lib/Sys/Hostname.pm U src/contrib/perl5/lib/Sys/Syslog.pm % ls -l src/contrib/perl5/lib/Sys/Hostname.pm -rw------- 1 pckizer staff 3126 Jul 19 1999 Hostname.pm Versions as provided by 'standard' perl5 as available from CTAN that do not have the problem: <http://www.FreeBSD.org/cgi/cvsweb.cgi/src/contrib/perl5/lib/Sys/Hostname.pm?rev=1.1> <http://www.FreeBSD.org/cgi/cvsweb.cgi/src/contrib/perl5/lib/Sys/Hostname.pm?rev=1.1.1.1> The patch is stil just as trivial: --- Hostname.pm.orig Fri Apr 7 16:12:04 2000 +++ Hostname.pm Fri Apr 7 19:22:51 2000 @@ -100,2 +100,3 @@ $ENV{'PATH'} = $pathstack; + $host; } @@ -109,2 +110,3 @@ $ENV{'PATH'} = $pathstack; + $host; } Looking closer at it there's another problem with it (not that it would be shown under FreeBSD given that /bin/hostname _will_ be there). If the same patch were put on some system where 'hostname' failed and a PATH is pre-defined, it would always take mathod 3 as having succeeded and never get to method 4. Am I missing something as to why my cvsup's don't have an updated version, or was this never actually committed? Thanks, -philip -- Philip Kizer <pckizer@tamu.edu>, 409.862.4120 Texas A&M CIS Operating Systems Group, Unix State Changed From-To: closed->open New evidence... :-) Responsible Changed From-To: sheldonh->markm Mark, can you check this out? State Changed From-To: open->closed As Perl is no longer part of the base, and as I can't reproduce this with the port, close. |
I'm sending this as a FreeBSD send-pr since the Sys/Hostname.pm that came with perl5.005_03 as of my latest cvsup this morning differs from the Sys/Hostname.pm as shipped with perl5.005_03 as distributed via CPAN. The Sys/Hostname.pm as cvsup-ed this morning differs from the CPAN distributed perl5.005_03 Sys/Hostname.pm as follows: --- /tmp/perl5.005_03/lib/Sys/Hostname.pm Thu Sep 2 18:13:51 1999 +++ Hostname.pm-orig Thu Sep 2 18:27:32 1999 @@ -95,4 +95,7 @@ || eval { + $pathstack = $ENV{'PATH'}; + $ENV{'PATH'} = "/bin:/usr/bin"; local $SIG{__DIE__}; $host = `(hostname) 2>/dev/null`; # bsdish + $ENV{'PATH'} = $pathstack; } @@ -101,4 +104,7 @@ || eval { + $pathstack = $ENV{'PATH'}; + $ENV{'PATH'} = "/bin:/usr/bin"; local $SIG{__DIE__}; $host = `uname -n 2>/dev/null`; ## sysVish + $ENV{'PATH'} = $pathstack; } The problem this causes is that the eval-ed blocks are guarenteed to be taken as having failed as they will exit with the undef from the $ENV{'PATH'} variable assignment in the case where there is no PATH defined prior to the function call (such as, in my case, an automated invocation from sendmail), Fix: The code blocks need to exit with a return value based on the success of the hostname determination. My quick fix was the following: How-To-Repeat: % /usr/bin/perl -e 'use Sys::Hostname; print Sys::Hostname::hostname(),"\n";' chariot.tamu.edu % env PATH= /usr/bin/perl -e 'use Sys::Hostname; print Sys::Hostname::hostname(),"\n";' Cannot get host name of local machine at -e line 1