简体   繁体   English

使用LD_PRELOAD和dlsym()覆盖'free'或'delete'

[英]Overriding 'free' or 'delete' using LD_PRELOAD & dlsym()

Overriding 'malloc' using the LD_PRELOAD mechanism 使用LD_PRELOAD机制覆盖'malloc'

How can LD_PRELOAD be used to set ptr to NULL or to any other memory address in order to avoid dangling pointer exploits. 如何使用LD_PRELOADptr设置为NULL或任何其他内存地址,以避免悬空指针攻击。

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. 使用LD_PRELOAD,您可以覆盖符号,例如函数。 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. 要更改传入free()的指针,您需要访问free()调用者的变量,以便将其设置为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 在这种情况下,没有变量设置为NULL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM