Re: [LIP] a strange problem.

"Amod Malviya" <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
you've opened the fd with permission of O_RDWR, which means you can read. Since you are now mapping it with PROT_READ permissions, its possible, since you opened the fd with read permissions enabled. Hence, the behaviour is alright.

--amod

----- Original Message -----
From: "sameer oak" <samunix-e99/[email protected]>
Date: Tue, 22 Jun 2004 09:15:04 -0700
To: linux-india-programmers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: [LIP] a strange problem.

kindly go through the following snippet:

 ...
 /* opens a file, initialises to 0 and maps into shared-memory */
 /*if((fd=open(*(argstr+1),O_RDWR|O_CREAT,FILE_MODE))<0)*/
 if((fd=open(*(argstr+1),O_RDONLY,FILE_MODE))<0)
 {
  fprintf(stderr,"file creation error for %s.\n%u: %s\n",*(argstr+1),\
          (unsigned)errno,strerror(errno));
  return 1;
 }
 /*if((write(fd,&shared,sizeof(struct shared)))<0)
 {
  fprintf(stderr,"file write error for %s.\n%u: %s\n",*(argstr+1),\
          (unsigned)errno,strerror(errno));
  return 1;
 }*/
 if((ptr=(struct shared *)mmap((void *)NULL,sizeof(struct shared),
          PROT_READ,MAP_SHARED,fd,0))==(struct shared *)MAP_FAILED)
 ...

i'm coming across a strange problem.
when a file is opened in  O_RDONLY and a call to mmap() with PROT
paramter value 
as PROT_READ|PROT_WRITE is made, it's giving an error: permission
denied, which 
is very appropriate.

but when i open a file in O_RDWR|O_CREAT and make a call to mmap() with
PROT 
paramter value as PROT_READ, it's letting me pass through the mmap() 
call. i'm expecting the same permission denied at this juncture.

can anyone please let me what's happenin' here?


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.