Subject: port-i386/759: Segmentation fault in _DYNAMIC () for static program
To: None <gnats-admin@NetBSD.ORG>
From: Simon J. Gerraty <sjg@zen.void.oz.au>
List: netbsd-bugs
Date: 01/28/1995 11:20:05
>Number:         759
>Category:       port-i386
>Synopsis:       statically linked program gets Segmentation fault in _DYNAMIC ()
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 28 11:20:04 1995
>Originator:     Simon J. Gerraty
>Organization:
Zen Programming...
>Release:        1.0
>Environment:
	
System: NetBSD zen.void.oz.au 1.0 NetBSD 1.0 (ZEN) #6: Tue Dec 13 09:55:20 EST 1994 root@zen.void.oz.au:/usr/src/sys/arch/i386/compile/ZEN i386


>Description:

I'm trying to debug a statically linked program, yet I keep getting a
seg fault in _DYNAMIC().  After that, gdb seems almost totally hosed.
I'd have said the segfault was coming from my program except that by
itself telnet was dumping core...

>How-To-Repeat:

cc -pipe  -static -o telnet authenc.o commands.o main.o network.o ring.o sys_bsd.o telnet.o terminal.o tn3270.o utilities.o ideaencc.o -static -L/e0/src/fwall/src/lib/obj.i386 -ltermcap -ltelnet  -lidearsa
sjg:3838$ gdb ./obj.i386/telnet                                      
(gdb) b privkey_gen
Breakpoint 1 at 0xc97b: file /e0/src/fwall/src/lib/libidearsa/privkey.c, line 36.
(gdb) r
Starting program: /e0/src/fwall/src/telnet/telnet/./obj.i386/telnet 
telnet> set options
Will show option processing.
telnet> open zen 4024
Trying 192.168.42.1...
SENT WILL IDEAENC
Connected to zen.void.oz.au.
Escape character is '^]'.
RCVD DO IDEAENC
RCVD IAC SB IDEAENC (unknown) 0 48 48 44 48 53 44 49 49 44 48 49 44 56 48 44 98 54 44 50 99 44 99 98 44 52 54 44 56 57 44 48 56 44 49 55 44 54 102 44 48 57 44 97 48 44 98 50 44 99 50 44 51 50 44 101 54 44 53 102 44 52 101 44 99 99 44 101 101 44 49 57 44 101 97 44 55 48 44 100 51 44 97 99 44 50 49 44 97 48 44 100 101 44 54 97 44 57 48 44 52 56 44 54 56 44 49 52 44 48 50 44 102 55 44 57 98 44 56 99 44 52 53 44 54 99 44 50 56 44 99 102 44 53 50 44 48 57 44 48 57 44 54 48 44 49 99 44 98 54 44 97 55 44 97 57 44 53 53 44

Breakpoint 1, privkey_gen (
    pubkey=0x314be "00,05,11,01,80,b6,2c,cb,46,89,08,17,6f,09,a0,b2,c2,32,e6,5f,4e,cc,ee,19,ea,70,d3,ac,21,a0,de,6a,90,48,68,14,02,f7,9b,8c,45,6c,28,cf,52,09,09,60,1c,b6,a7,a9,55,") at /e0/src/fwall/src/lib/libidearsa/privkey.c:36
36              CLEAR(pk);
(gdb) n
37              CLEAR(pn);
(gdb) 
38              CLEAR(pe);
(gdb) 
40              pub = str2key(pubkey);
(gdb) 
43              i = mpi2reg(pe, pub);
(gdb) 
44              mpi2reg(pn, &pub[i + 2]);
(gdb) 
49              randload(128);
(gdb) 
50              (void) randombyte();                    /* skip the first */
(gdb) 
52              for (i = 0; i < sizeof (ik); i++) {
(gdb) b 60
Breakpoint 2 at 0xca06: file /e0/src/fwall/src/lib/libidearsa/privkey.c, line 60.
(gdb) c
Continuing.

Breakpoint 2, privkey_gen (pubkey=0xf7bfd568 "j4FHY,\225\202Rcx1((K`")
    at /e0/src/fwall/src/lib/libidearsa/privkey.c:60
60              if (rsa_public_encrypt((unitptr) pk, ik, sizeof (ik), pe, pn) < 0) {
(gdb) p/x ik
$2 = {0x6a, 0xb4, 0xc6, 0x48, 0xd9, 0xac, 0x95, 0x82, 0x52, 0x63, 0x78, 0x31, 
  0x28, 0xa8, 0x4b, 0xe0}
(gdb) n

Program received signal SIGSEGV (11), Segmentation fault
0x0 in _DYNAMIC ()
(gdb) 

at that point 'q' is the only thing gdb handles.

$ file ./obj.i386/telnet
./obj.i386/telnet: NetBSD/i386 demand paged executable not stripped

There are correct prototypes in scope for rsa_public_encrypt() etc.

I'm sure there is probably a bug in my program... but what is upseting gdb?
>Fix:
>Audit-Trail:
>Unformatted: