mallocat func needed

D

Don Betts

Hi all,

our app crashes because it derefs null ptrs. guy who quit caused this.
boss want to see if we can fix it quick. can we malloc mem at addr 0 so
null ptrs dont' cause core dump? we need mallocat func like this
mallocat(size, addr)
then we call it mallocat(size,0) and no more crach. is there mallocat
func in linux c? plz let me know. thanks in adv...db
ps, email replies to me cause i have iphone and need quick response :)
 
I

Ian Collins

Don said:
Hi all,

our app crashes because it derefs null ptrs.

Then fix them.
guy who quit caused this.
boss want to see if we can fix it quick. can we malloc mem at addr 0 so
null ptrs dont' cause core dump?

That would only work once, if at all.

Then fix them.
ps, email replies to me cause i have iphone and need quick response :)

iPhone is a success because it's code doesn't dereference null pointers.

Then fix them.
 
J

jameskuyper

Don said:
Hi all,

our app crashes because it derefs null ptrs. guy who quit caused this.
boss want to see if we can fix it quick. can we malloc mem at addr 0 so
null ptrs dont' cause core dump? we need mallocat func like this
mallocat(size, addr)
then we call it mallocat(size,0) and no more crach. is there mallocat
func in linux c? plz let me know. thanks in adv...db

If your app dereferences null pointers, that's because it's lost track
of (or never knew in the first place) the location that the pointer
was supposed to point at. Until you fix that problem, your program
will work only by accident, and even if mallocat() were a possibility,
it wouldn't solve that problem.

Look at it this way: if you have a value of 3 stored in a given
location in memory, and the pointer is supposed to point at that
location, and there's a bug in the program that results in the pointer
being null instead of pointing at that location, how are you going to
retrieve the 3? Letting a null pointer reference work wouldn't help
even if it were possible, because the 3 will be somewhere else, not at
the location the null pointer points at.

Let's say that both the writing of the value and the reading of it are
both done to the same location you've allocated with a hypothetical
mallocat(). Does that solve your problem? Probably not. If there's one
such error in this code, there's probably more than one. If one part
of your code stores 42.0 in that location, then another part stores
"Help - I was programmed by an idiot!" in that same location, then a
third program tries to retrieve the 42.0, it's probably not going to
find it. It's going to reinterpret the bits representing that string
as of they represented a floating point number. If you're lucky, it
will interpret them as a signaling NaN which will cause your program
to fail before it does any more damage. If you're unlucky, it will
interpret it as an ordinary, large, negative number, and add that
amount to your companies bank balance.
 
K

Kaz Kylheku

Hi all,

our app crashes because it derefs null ptrs. guy who quit caused this.
boss want to see if we can fix it quick. can we malloc mem at addr 0 so
null ptrs dont' cause core dump? we need mallocat func like this
mallocat(size, addr)

Look up the mmap function. It can map at a fixed address with MAP_FIXED.

The page at adress zero is normally unmapped, so that null pointer
dereferences, or most references relative to a null pointer, are trapped.
then we call it mallocat(size,0) and no more crach.

The problem is that the application has some bugs.

It probably references the null pointers for a reason. It thinks that there is
a unique object located at that address. It wants to retrieve a value from
there and perhaps update the value.

If you allow null pointers to be used, then different modules of the program
will use the same null pointer area, overwriting each other's data.
 
C

CBFalconer

Don said:
our app crashes because it derefs null ptrs. guy who quit caused
this. boss want to see if we can fix it quick. can we malloc mem
at addr 0 so null ptrs dont' cause core dump? we need mallocat
func like this mallocat(size, addr) then we call it
mallocat(size,0) and no more crach. is there mallocat func in
linux c? plz let me know. thanks in adv...db ps, email replies to
me cause i have iphone and need quick response :)

You need to do the work to fix the source. Any such thing will
simply ignore the errors, and prevent finding them in future.
 
L

luserXtrog

Hi all,

our app crashes because it derefs null ptrs.

Ok so far.
guy who quit caused this.

Not really relevant. Inferring dull axe.
boss want to see if we can fix it quick.

Yes, well quick fixes are usually the best, aren't they?
can we malloc mem at addr 0 so
null ptrs dont' cause core dump?

Typically, no. Often, low memory addresses are reserved
for possibly important things like interrupt vectors.
we need mallocat func like this
mallocat(size, addr)
then we call it mallocat(size,0) and no more crach.

Unless Mollochat is on good terms with the Oracle of Turing,
it's unlikely to have strong enough magic to solve this for
you.
is there mallocat
func in linux c?

Investigate "man man".
plz let me know.

We live but to serve.
thanks in adv...db
ps, email replies to me cause i have iphone and need quick response :)

I just can't stop giggling at this part.
There's just so many loose ends to this!

This is what you appear to be describing.
Perhaps it will help clarify your issue.

void *mallocat(size_t size, void *addr){
while(size--) ((unsigned char *)addr)[size-1] = 0xF00L;
return addr;
}

This function attempts to fill the specified memory
location with garbage bytes whose value will be 0 on an 8bit
machine and <0 on a 9bit machine. It also returns that pointer
if it is somehow able to return at all.

Patient: It hurts when I do this.
Doctor: Don't do that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,587
Members
45,092
Latest member
vinaykumarnevatia1

Latest Threads

Top