Bug 21719 - program using "initgroups()" fails with stack corruption
Summary: program using "initgroups()" fails with stack corruption
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-05-23 13:58 UTC by Ulrich Windl
Modified: 2005-07-23 22:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build: hppa2.0w-hpux11.11
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Log file with revised source, disassemblies for both compilers (574 bytes, text/plain)
2005-05-24 08:31 UTC, Ulrich Windl
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ulrich Windl 2005-05-23 13:58:29 UTC
Tracing down a problem with sudo receiving a stack corruption on one machine,
I've found out that a minimal program gets a stack corruption when compiled with
gcc-3.4.3, but not when being compiled with HP's bundled "cc". See details here:
http://www.sudo.ws/bugs/show_bug.cgi?id=170#c26

The minimal program is this:
main()
{
    initgroups("root", 3);
}

Possible required further conditions are: /etc/group must have "+:" in the last
line, /etc/nsswitch.conf should have "compat" for selector "groups", and the
machine should be NIS master server. (When removing the "+:" from /etc/group,
the gcc-compiled binary also doesn't get a memory fault).
I'd like to file a bug report for the HP C library once I know it's not a gcc
bug. Upon request I can attach or include disassemblies of both, HP-CC code, and
 GCC code.
Comment 1 Andrew Pinski 2005-05-23 14:02:34 UTC
This really sounds like a HP C library bug or bug in the code but I don't know for sure.  You are using 
old style K&R C, can you use -Wall -W and fix all the warnings?
Comment 2 Ulrich Windl 2005-05-24 08:31:44 UTC
Created attachment 8958 [details]
Log file with revised source, disassemblies for both compilers

I've revised the source to fix all warnings (except unused formal parameters).
Including the declaration or not does not make any difference BTW. I've also
added gdb's disassembly of function main for both compilers; gcc-3.4.3, and
that of HP-UX 11.11. Finally let me remark that the OS runs 64 bit, but all
binaries are 32 bit (which is no problem at all).
Comment 3 Steve Ellcey 2005-05-31 17:38:05 UTC
This seems more likely to be an HP library bug.  I recommend trying the latest
libc patch for HP-UX 11.11, PHCO_31903.  There is a reference to the HP defect
JAGad41604 that may be causing your problem.  I don't know why it wouldn't fail
when compiled with HP'c C.
Comment 4 Ulrich Windl 2005-06-01 06:14:19 UTC
Just for reference: The machine in question does not have C-library patch
PHCO_31903 installed, but the quoted defect (JAGad41604) doesn't seem to be
relevant (The system isn't a trusted one, and only the "hosts" entry in
/etc/nsswitch.conf uses "dns", while the "group" entry uses "compat").
I'm hoping someone who really understands the PA assembler can compare the
assembly code of both compilers and find out whether there's a significant
difference. Having something like Linux' "ltrace" or "valgrind" for HP-UX would
be great to track down that problem.
Comment 5 Andrew Pinski 2005-06-01 19:52:22 UTC
Not a GCC bug.