This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/2007] mmap seg faults on marginally improper arguments


------- Additional Comments From mv at binarysec dot com  2005-12-25 17:52 -------
Subject: Re:  mmap seg faults on marginally improper arguments

We don't know how your text_mmap() does to work.

On Dec 24, 2005, at 8::32::56GMT+04:00, bkorb at gnu dot org wrote:

>
> ------- Additional Comments From bkorb at gnu dot org  2005-12-24  
> 16:32 -------
> I do not have an Alpha platform and the problem does not exist
> on my Linux/i386 platform.  I was pretty sure at the time that
> I wrote this report that the cause was more likely to be in the
> kernel than in glibc.  Leastwise, I was guessing that the mmap
> code for Linux/Alpha was not going to be much different from
> any other platform.  If that code is not any different, then some
> variation in kernel behavior triggered the fault.  Is that a
> kernel problem or a glibc problem?  I don't know.  I don't want
> to be in the middle.
>
>
>
> #include <sys/types.h>
> #include <sys/mman.h>
> #include <sys/stat.h>
>
> #include <stdio.h>
> #include <fcntl.h>
> #include <stdint.h>
> #include <unistd.h>
>
> typedef struct {
>     void*       txt_data;      /* text file data   */
>     size_t      txt_size;      /* actual file size */
>     size_t      txt_full_size; /* mmaped mem size  */
>     int         txt_fd;        /* file descriptor  */
>     int         txt_zero_fd;   /* fd for /dev/zero */
>     int         txt_errno;     /* warning code     */
>     int         txt_prot;      /* "prot" flags     */
>     int         txt_flags;     /* mapping type     */
>     int         txt_alloc;     /* if we malloced memory */
> } tmap_info_t;
>
> int
> main(int argc, char** argv)
> {
>     {
> 	int  fd = open( "/tmp/FOO", O_CREAT | O_WRONLY, 0666 );
>         long sz = sysconf( _SC_PAGESIZE );
> 	char z[ 16 ];
>
> 	if (fd < 0) exit(1);
> 	while (sz > 0) {
> 	    sprintf( z, "0x%4X..", sz );
> 	    write( fd, z, 8 );
> 	    sz -= 8;
> 	}
> 	close(fd);
>     }
>
>     {
> 	tmap_info_t mi;
> 	void* ptr =
> 	    text_mmap( "/tmp/FOO", PROT_READ|PROT_WRITE, MAP_PRIVATE, &mi );
> 	fputs( "This platform does not fail\n", stdout );
> 	text_munmap( &mi );
>     }
>
>     return 1;
> }
>
> -- 
>
>
> http://sourceware.org/bugzilla/show_bug.cgi?id=2007
>
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug, or are watching someone who is.




-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=2007

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]