lkml.org 
[lkml]   [1999]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: sed not working on /proc files
Date
From
Alan Cox wrote:
> > > Well, this breaks every program that uses libc file accesses.
> > So fix the buggy libc. Relying on mmap() being available is broken
>
> To save a thousand follow ups - the glibc code does do the right thing but
> the kernel thinks any 0 length mmap succeeds and doesnt error it. So its
> a kernel funny


] unsigned long do_mmap(struct file * file, unsigned long addr, unsigned long len,
] unsigned long prot, unsigned long flags, unsigned long off)
] {
] struct mm_struct * mm = current->mm;
] struct vm_area_struct * vma;
] int error;
]
] if ((len = PAGE_ALIGN(len)) == 0)
] return addr;

And "here" is where this happens.

Wouldn't it be better to just do "return NULL"?

There you have a perfectly valid pointer to access the 0 bytes that
you asked for.

Just like "malloc (0)" returns NULL on some systems: You're toast when
you dare dereference the pointer (beyond what you asked for). (and feel
free not to free/munmap it afterwards.)


The "files" in /proc should in my opinion not pretend to be files:
they should be "pipes". Many programs stat their input file, and if
they get "normal file", they have all sorts of assumptions on tricks
they can do.

For example, "wc -c" will just return the st_size of the file, instead
of doing all the work that is normally involved in counting the file.


Roger.


--
** R.E.Wolff@BitWizard.nl ** http://www.BitWizard.nl/ ** +31-15-2137555 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
------ Microsoft SELLS you Windows, Linux GIVES you the whole house ------


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:51    [W:0.084 / U:1.312 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site