Bug 103338 - shmat() fails when binary is linked with libncurses
shmat() fails when binary is linked with libncurses
Product: Red Hat Enterprise Linux 2.1
Classification: Red Hat
Component: kernel (Show other bugs)
ia64 Linux
medium Severity medium
: ---
: ---
Assigned To: Jim Paradis
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2003-08-28 20:42 EDT by umut
Modified: 2013-08-05 21:02 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-06-08 17:37:51 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description umut 2003-08-28 20:42:59 EDT
Description of problem:
When the binary is linked with libncurses(-lncurses), shmat() call failes with -
1 trying to attach to an allocated shared memory segment.

The shared memory segment was allocated and attached by a binary "a".
shmat() was called by a binary "b" using the same shmid and shmkey and the same 
attached address returned by binary "a".

The problem does not reproduce when the binary "b" was not linked with 

Version-Release number of selected component (if applicable):

How reproducible:
every time

Steps to Reproduce:
1.compile binary a (gcc3 -o a a.c)
2.compile binary b with -lncurses (gcc3 -o b b.c -lncurses)
3.run b with the address from a
Actual results:
0xffffffffffffffff from b

Expected results:
valid address

Additional info:
#include <stdio.h>
#include <sys/types.h>
#include <sys/shm.h>


unsigned int segsize = 512*1024;
int                     shmid;
key_t               shmkey = 123456789;
void * adr;

shmid = shmget(shmkey, segsize,IPC_CREAT|0660);
adr = shmat(shmid, 0,0);

printf("shmid = %d  adr = %p\n",shmid, adr);

#include <stdio.h>
#include <stdlib.h>
#include <sys/shm.h>

main(int argc, char **argv)
 void * addr1, * addr2;
key_t  shmkey = 123456789;
int shmid;

addr1 = (void*) strtoul(argv[1],NULL,0);
shmid = shmget(shmkey, 0, 0660);

addr2 = shmat(shmid, addr1, 0);
printf("addr2 = %p\n",addr2);

%gcc3 -o a a.c
%gcc3 -o b b.c
%gcc3 -o c b.c -lncurses

% ./a
shmid = 313556996 adr = 0x2000000000300000

%./b 0x2000000000300000
addr2 = 0x2000000000300000

%./c 0x2000000000300000
addr2 = 0xffffffffffffffff
Comment 1 umut 2003-08-28 20:45:10 EDT
kernel version is kernel-2.14.18-e.12
Comment 2 Arjan van de Ven 2003-08-29 04:35:11 EDT
does this happen also when you actually use a supported gcc version ?
Comment 3 umut 2003-08-29 12:44:49 EDT
i could also reproduce with the gcc version 2.96-112.7.2  I have downloaded 
gcc3 from the rhn.redhat.com and we are using that currently.
Comment 4 Jim Paradis 2006-06-08 17:37:51 EDT
RHEL2.1 is currently accepting only critical security fixes.  This issue is
outside the current scope of support.

Note You need to log in before you can comment on or make changes to this bug.