adarshanto has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to initialize Perl interpreter (Perl-5.8.5) from my C program (using perl_run())
It is crashing (SIGSEGV) in HPUX trusted systems during the init.
Same program works fine for HPUX non-trusted systems & other operating systems like Linux, AIX & Solaris.

Gives me this error message:
Program received signal SIGSEGV, Segmentation fault.
0x00706424 in Perl_pp_gpwent (my_perl=0x40278470) at pp_sys.c:5310

During the initialization, getspnam() function is invoked.
The function returns an invalid address in HPUX trusted systems & the program crashes trying to access the memory.
Ideally, the function should return NULL pointer in case of failure & the program should be working fine.

Please help me to fix this issue
Many thanks in Advance

Code snippet where issue happens follows: (File: perl-5.8.5/pp_sys.c:5310)
5299 # if defined(HAS_GETSPNAM) && !defined(_AIX) 5300 { 5301 struct spwd *spwent; 5302 int saverrno; /* Save and restore errno so that 5303 * underprivileged attempts seem 5304 * to have never made the unsccessful 5305 * attempt to retrieve the shadow password. */ 5306 5307 saverrno = errno; 5308 spwent = getspnam(pwent->pw_name); 5309 errno = saverrno; 5310 if (spwent && spwent->sp_pwdp) 5311 sv_setpv(sv, spwent->sp_pwdp); 5312 }

(gdb) p *pwent
$1 = {pw_name = 0x40280d40 "root", pw_passwd = 0x40280d45 "*", pw_uid = 0, pw_gid = 3, pw_age = 0x40280d46 "", pw_comment = 0x40280d4b "",
pw_gecos = 0x40280d4b "", pw_dir = 0x40280d4c "/", pw_shell = 0x40280d4e "/usr/bin/ksh", pw_audid = 1076358392, pw_audflg = 1}

After the getspnam() call:
(gdb) p *spwent
Cannot access memory at address 0x64726976
(gdb)

Machine details:
bash-4.2# uname -a
HP-UX hprp3440 B.11.31 U 9000/800 458296442 unlimited-user license

Complete backtrace:
Program received signal SIGSEGV, Segmentation fault.
0x00706424 in Perl_pp_gpwent (my_perl=0x40278470) at pp_sys.c:5310
(gdb) bt
#0 0x00706424 in Perl_pp_gpwent (my_perl=0x40278470) at pp_sys.c:5310
#1 0x007060a4 in Perl_pp_gpwuid (my_perl=0x77fb2d94) at pp_sys.c:5154
#2 0x00674c4c in Perl_runops_debug (my_perl=0x40278470) at dump.c:1442
#3 0x0062b3a0 in S_call_body (my_perl=0x40278470, myop=0xe, is_eval=2012531840) at perl.c:2288
#4 0x0062af8c in Perl_call_sv (my_perl=0x40278470, sv=0x0, flags=6) at perl.c:2206
#5 0x0062f548 in S_call_list_body (my_perl=0x40278470, cv=0x40ce0ef8) at perl.c:4698
#6 0x0062f0b4 in Perl_call_list (my_perl=0x40278470, oldscope=24, paramList=0x40ce0e5c) at perl.c:4627
#7 0x006598d8 in Perl_newATTRSUB (my_perl=0x40278470, floor=852, o=0x40ce0ef8, proto=0x18, attrs=0x0, block=0x40ce21c0) at op.c:4416
#8 0x00656100 in Perl_utilize (my_perl=0x40278470, aver=1, floor=852, version=0x40ce21c0, idop=0x40ce1268, arg=0x0) at op.c:2992
#9 0x006dde44 in Perl_yyparse (my_perl=0x40278470) at perly.y:414
#10 0x006ad1f0 in S_doeval (my_perl=0x40278470, gimme=0, startop=0x0, outside=0x4029cc08, seq=9) at pp_ctl.c:2817
#11 0x006aef08 in Perl_pp_entereval (my_perl=0x40278470) at pp_ctl.c:3411
#12 0x00674c4c in Perl_runops_debug (my_perl=0x40278470) at dump.c:1442
#13 0x0062b3a0 in S_call_body (my_perl=0x40278470, myop=0xe, is_eval=2012531840) at perl.c:2288
#14 0x0062af8c in Perl_call_sv (my_perl=0x40278470, sv=0x0, flags=6) at perl.c:2206
#15 0x0062f548 in S_call_list_body (my_perl=0x40278470, cv=0x40cc8650) at perl.c:4698
#16 0x0062f0b4 in Perl_call_list (my_perl=0x40278470, oldscope=17, paramList=0x40cc8590) at perl.c:4627
#17 0x006598d8 in Perl_newATTRSUB (my_perl=0x40278470, floor=616, o=0x40cc8650, proto=0x11, attrs=0x0, block=0x40be0610) at op.c:4416
#18 0x00656100 in Perl_utilize (my_perl=0x40278470, aver=1, floor=616, version=0x40be0610, idop=0x40ba6f50, arg=0x0) at op.c:2992
#19 0x006dde44 in Perl_yyparse (my_perl=0x40278470) at perly.y:414
#20 0x006ad1f0 in S_doeval (my_perl=0x40278470, gimme=0, startop=0x0, outside=0x4029cc08, seq=9) at pp_ctl.c:2817
#21 0x006aef08 in Perl_pp_entereval (my_perl=0x40278470) at pp_ctl.c:3411
#22 0x00674c4c in Perl_runops_debug (my_perl=0x40278470) at dump.c:1442
#23 0x0062b3a0 in S_call_body (my_perl=0x40278470, myop=0xe, is_eval=2012531840) at perl.c:2288
#24 0x0062af8c in Perl_call_sv (my_perl=0x40278470, sv=0x0, flags=6) at perl.c:2206
#25 0x0062f548 in S_call_list_body (my_perl=0x40278470, cv=0x40682e08) at perl.c:4698
#26 0x0062f0b4 in Perl_call_list (my_perl=0x40278470, oldscope=10, paramList=0x40682dd8) at perl.c:4627
#27 0x006598d8 in Perl_newATTRSUB (my_perl=0x40278470, floor=383, o=0x40682e08, proto=0xa, attrs=0x0, block=0x402cbe98) at op.c:4416
#28 0x00656100 in Perl_utilize (my_perl=0x40278470, aver=1, floor=383, version=0x402cbe98, idop=0x402c4378, arg=0x0) at op.c:2992
#29 0x006dde44 in Perl_yyparse (my_perl=0x40278470) at perly.y:414
#30 0x006ad1f0 in S_doeval (my_perl=0x40278470, gimme=0, startop=0x0, outside=0x4029cc08, seq=9) at pp_ctl.c:2817
#31 0x006aef08 in Perl_pp_entereval (my_perl=0x40278470) at pp_ctl.c:3411
#32 0x00674c4c in Perl_runops_debug (my_perl=0x40278470) at dump.c:1442
#33 0x0062b3a0 in S_call_body (my_perl=0x40278470, myop=0xe, is_eval=2012531840) at perl.c:2288
#34 0x0062af8c in Perl_call_sv (my_perl=0x40278470, sv=0x0, flags=6) at perl.c:2206
#35 0x0062f548 in S_call_list_body (my_perl=0x40278470, cv=0x40682d18) at perl.c:4698
#36 0x0062f0b4 in Perl_call_list (my_perl=0x40278470, oldscope=3, paramList=0x4028c2b4) at perl.c:4627
#37 0x006598d8 in Perl_newATTRSUB (my_perl=0x40278470, floor=154, o=0x40682d18, proto=0x3, attrs=0x0, block=0x402aa238) at op.c:4416
#38 0x00656100 in Perl_utilize (my_perl=0x40278470, aver=1, floor=154, version=0x402aa238, idop=0x402a4710, arg=0x0) at op.c:2992
#39 0x006dde44 in Perl_yyparse (my_perl=0x40278470) at perly.y:414
#40 0x006ad1f0 in S_doeval (my_perl=0x40278470, gimme=0, startop=0x0, outside=0x40279230, seq=0) at pp_ctl.c:2817
#41 0x006aef08 in Perl_pp_entereval (my_perl=0x40278470) at pp_ctl.c:3411
#42 0x0062b370 in S_call_body (my_perl=0x40278470, myop=0xe, is_eval=2012531840) at perl.c:2283
#43 0x0062b634 in Perl_eval_sv (my_perl=0x40278470, sv=0x402790f8, flags=0) at perl.c:2348
#44 0x0062b8b0 in Perl_eval_pv (my_perl=0x40278470, p=0xe <Address 0xe out of bounds>, croak_on_error=1) at perl.c:2407
#45 0x001f2b58 in swzl_perl_run () at ../cli/swzl_perl.c:103

Replies are listed 'Best First'.
Re: Perl Interpreter (5.8.5) initialization causes SIGSEGV in HPUX
by Corion (Patriarch) on Aug 15, 2012 at 06:34 UTC

    Perl 5.8.5 is really old. It is not even the latest in the 5.8 series. Consider using at least 5.8.9 (the last in the 5.8 series), or consider using a supported version of Perl, like 5.14 or 5.16.

    If you are compiling Perl from source and yet cannot change the 5.8.5 version, I recommend looking through the changes to pp_sys.c after 5.8.5. Maybe that bug was fixed for HPUX. The blame log for pp_sys.c may or may not help there.

Re: Perl Interpreter (5.8.5) initialization causes SIGSEGV in HPUX
by Tux (Canon) on Aug 15, 2012 at 12:36 UTC

    Is the number of users (/etc/passwd) on the trusted system "huge"? There are known crashers on HP-UX and Windows (and probably more) for systems that host a rather high number of users. It is not depending on how many users are currently logged in, but on the number of user id's the system knows about.

    I /think/ it is fixed in more recent versions of perl, but I never had access to a trusted HP-UX with a high number of known users.

    More recent ports for perl are available on HP's site (5.8.8), the HP porting center (5.10.1) or on my site (all up to and including 5.16.0).


    Enjoy, Have FUN! H.Merijn

      There are around 22 entries in the /etc/password file
      However, only 1 or 2 users are simultaneously logged in

      I also checked pp_syc.c file upto 5.16.0
      The mentioned code snippet didn't have any significant code changes- apart from the following minor change:

      dSAVE_ERRNO; const struct spwd * const spwent = getspnam(pwent->pw_name); RESTORE_ERRNO;

      Will try to make the change which rurban suggested: Try to disable HAS_GETSPNAM in config.h
      Searched all the c files and found that HAS_GETSPNAM is used only at this place.
      Please let me know if you think this may have any undesirable side effects

        I disabled HAS_GETSPNAM & the crash was fixed
        Thanks again for promptly jumping in to help

Re: Perl Interpreter (5.8.5) initialization causes SIGSEGV in HPUX
by rurban (Scribe) on Aug 15, 2012 at 18:52 UTC
    blead also has not much more protection other then
    dSAVE_ERRNO; const struct spwd * const spwent = getspnam(pwent->pw_name); RESTORE_ERRNO;
    You can try to disable HAS_GETSPNAM in config.h after Configure.