禁用的malloc的随机性 [英] disable the randomness in malloc

查看:196
本文介绍了禁用的malloc的随机性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑这下面简单的C程序:

I'm running this following simple C program:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv){
  void *p = malloc(4);
  fprintf (stderr, "p==%p\n", p);
  return 0;
}

不同的运行得到不同的结果:

Different runs give different results:

点== 0x101c010

p==0x101c010

然后:P == 0x1ad9010

then: p==0x1ad9010

然后:P == 0xe77010

then: p==0xe77010

等。

我记得,在过去的malloc是完全确定的。所以大概一些版本,一些随机性加入的malloc。
我使用在Ubuntu现在GCC-4.6.3。

As I remember, in the past malloc was fully deterministic. So probably from some version, some randomness was added to malloc. I am using now gcc-4.6.3 on Ubuntu.

有没有办法来eliminite随机性?

Is there a way to eliminite that randomness ?

推荐答案

如果变化是通过地址空间布局随机化造成的,那么,根据<一个href=\"http://askubuntu.com/questions/318315/how-can-i-temporarily-disable-aslr-address-space-layout-randomization\">this页面,您可以禁用它:

If the variation is caused by address space layout randomization, then, according to this page, you can disable it with:

echo 0 | sudo tee /proc/sys/kernel/randomize_va_space

这应该只是暂时用于调试完成。

This should be done only temporarily for debugging purposes.

这是插入功能的好纸:的在Windows,UNIX和Macintosh OS X平台的由丹尼尔·S·迈尔斯和Adam L. Bazinet的拦截任意函数。这将让你与一个完全可控的实现替换的malloc 行为。

This is a good paper on interposing functions: Intercepting Arbitrary Functions on Windows, UNIX, and Macintosh OS X Platforms by Daniel S. Myers and Adam L. Bazinet. This would allow you to replace the malloc behavior with a completely controlled implementation.

这篇关于禁用的malloc的随机性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆