Bug 103338 - shmat() fails when binary is linked with libncurses
Summary: shmat() fails when binary is linked with libncurses
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 2.1
Classification: Red Hat
Component: kernel
Version: 2.1
Hardware: ia64
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jim Paradis
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-08-29 00:42 UTC by umut
Modified: 2013-08-06 01:02 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-06-08 21:37:51 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description umut 2003-08-29 00:42:59 UTC
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 
libncurses.

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:
a.c:
-----
#include <stdio.h>
#include <sys/types.h>
#include <sys/shm.h>

main()
{

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);
}


b.c:
-----
#include <stdio.h>
#include <stdlib.h>
#include<sys/types.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-29 00:45:10 UTC
kernel version is kernel-2.14.18-e.12

Comment 2 Arjan van de Ven 2003-08-29 08:35:11 UTC
does this happen also when you actually use a supported gcc version ?


Comment 3 umut 2003-08-29 16:44:49 UTC
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 21:37:51 UTC
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.