[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

[ID 20000120.002] Sys::Hostname should use POSIX::uname on Unix




This is a bug report for perl from dhd@blood-axp.eradicator.org,
generated with the help of perlbug 1.26 running under perl 5.00503.


-----------------------------------------------------------------
[Please enter your report here]

Hi,

Sys::Hostname does not work in programs that use taint checking on i386
GNU/Linux systems.  The reason for this is that it tries to use the
'gethostname' system call, which does not exist on Linux/i386, and "gives
up" (by calling `hostname`) immediately afterwards.

The best way I can see to fix this is simply to add another method to the
$^O="Unix" condition in Sys::Hostname::hostname() that uses the $nodename
value returned by POSIX::uname().  Note that this is the way the
gethostname(2) C library function is implemented on Linux/i386.

You could also use the 'uname' system call, but I don't see why, since
POSIX.pm is standard nowadays.  Also many installations of GNU/Linux on
non-i386 platforms seem to have i386 system call numbers in syscall.ph (yes,
Linux's inconsistent system call numbering is somewhat broken - but you're
really not supposed to use system calls :)

Also, another Evil thing about Sys::Hostname is that it exports the
syscall.ph constants into package main.  I don't see any good reason to do
this, do you?

Here's a patch:

--- /usr/lib/perl5/5.005/Sys/Hostname.pm	Sun Jan 16 03:14:56 2000
+++ /home/infolynx/lib/Sys/Hostname.pm	Thu Jan 20 16:53:43 2000
@@ -67,43 +67,43 @@
   }
   else {  # Unix
 
-    # method 2 - syscall is preferred since it avoids tainting problems
+    # method 2 - use POSIX.pm, prefer the standard library to system calls
     eval {
 	local $SIG{__DIE__};
-	{
-	    package main;
-	    require "syscall.ph";
-	}
+	require POSIX;
+	$host = (POSIX::uname())[1];
+    }
+    # method 3 - otherwise syscall is preferred since it avoids tainting problems
+    || eval {
+	local $SIG{__DIE__};
+	require "syscall.ph";
 	$host = "\0" x 65; ## preload scalar
-	syscall(&main::SYS_gethostname, $host, 65) == 0;
+	syscall(&SYS_gethostname, $host, 65) == 0;
     }
 
-    # method 2a - syscall using systeminfo instead of gethostname
+    # method 3a - syscall using systeminfo instead of gethostname
     #           -- needed on systems like Solaris
     || eval {
 	local $SIG{__DIE__};
-	{
-	    package main;
-	    require "sys/syscall.ph";
-	    require "sys/systeminfo.ph";
-	}
+	require "sys/syscall.ph";
+	require "sys/systeminfo.ph";
 	$host = "\0" x 65; ## preload scalar
-	syscall(&main::SYS_systeminfo, &main::SI_HOSTNAME, $host, 65) != -1;
+	syscall(&SYS_systeminfo, &SI_HOSTNAME, $host, 65) != -1;
     }
 
-    # method 3 - trusty old hostname command
+    # method 4 - trusty old hostname command
     || eval {
 	local $SIG{__DIE__};
 	$host = `(hostname) 2>/dev/null`; # bsdish
     }
 
-    # method 4 - sysV uname command (may truncate)
+    # method 5 - sysV uname command (may truncate)
     || eval {
 	local $SIG{__DIE__};
 	$host = `uname -n 2>/dev/null`; ## sysVish
     }
 
-    # method 5 - Apollo pre-SR10
+    # method 6 - Apollo pre-SR10
     || eval {
 	local $SIG{__DIE__};
 	($host,$a,$b,$c,$d)=split(/[:\. ]/,`/com/host`,6);

[Please do not change anything below this line]
-----------------------------------------------------------------

---
Site configuration information for perl 5.00503:

Configured by chris at Sun Jan 16 02:52:04 EST 2000.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.2.14pre9, archname=alpha-linux
    uname='linux spawn 2.2.14pre9 #2 wed dec 15 00:24:37 est 1999 alpha unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=2.95.2 19991109 (Debian GNU/Linux)
    cppflags='-Dbool=char -DHAS_BOOL -D_REENTRANT -DDEBIAN -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -D_REENTRANT -DDEBIAN -I/usr/local/include'
    stdchar='char', d_stdstdio=undef, usevfork=false
    intsize=4, longsize=8, ptrsize=8, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldbm -ldb -ldl -lm -lc -lposix -lcrypt
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl 5.00503:
    /usr/lib/perl5/5.005/alpha-linux
    /usr/lib/perl5/5.005
    /usr/local/lib/site_perl/alpha-linux
    /usr/local/lib/site_perl
    /usr/lib/perl5
    .

---
Environment for perl 5.00503:
    HOME=/home/dhd
    LANG=C
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/bin:/usr/bin:/usr/bin/X11:/usr/local/bin:/usr/games
    PERL_BADLANG (unset)
    SHELL=/bin/bash


[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]