문제

Overriding 'malloc' using the LD_PRELOAD mechanism

How can LD_PRELOAD be used to set ptr to NULL or to any other memory address in order to avoid dangling pointer exploits.

void free(void *ptr)
{
    real_free(ptr);

    ptr = NULL // will only set local ptr to NULL
}
도움이 되었습니까?

해결책

It cannot.

With LD_PRELOAD you can override symbols, such as a function. To alter the pointer passed in to free() you would need access to the variable of the caller of free() in order to set it to NULL. But you only have access to a copy of the pointer passed in.

Note that a caller might even do something as:

 free(do_something()); 

In which case there is no variable to set to NULL

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top