| 您的位置: >> 相关知识 >> WEB开发 >> WINDOWS >> |
|
合金网络科技 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 添加日期:2007-3-30 点击次数:58次 |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
运行后发现溢出: ![]() 第二步: 修改buf的内容为: #include #include int overflow(char *buf) { char output[8]; strcpy(output,buf); printf('buf的地址是:%p\n',buf); printf('output内容为:%s\n',output); return 0; } int main() { char buf[26]; for(int j=0;j<26;j++) { buf[j]=97+j%10; } overflow(buf); return 0; } 编译执行缓冲溢出: ![]() 第三步: 将buf的内容改为整除: #include #include int overflow(char *buf) { char output[8]; strcpy(output,buf); printf('buf的地址是:%p\n',buf); printf('output内容为:%s\n',output); return 0; } int main() { char buf[26]; for(int j=0;j<26;j++) { buf[j]=97+j/10; } overflow(buf); return 0; } 编译执行溢出: ![]() 结果分析: 第一步中我们在buf中填充了26个A,导致溢出产生; 第二步中,buf中仍然填充了26个字符,但此时字符是有规律的按照a~j(十进制ASCII码为97~107)循环连接成的一个长度为26的字符串。为什么是这样?因为我们用10取余,余数一定不会大于10,加上97,其范围就为97~107啦。呵呵 第三步中,我们将j用10整除,那就是将这个长度为26的字符串按10位一段,分成了三段,各段中填充的字符相同(见图中的output内容为) |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "凌风微型文章系统",针对"搜索引擎"完美设计,提高"搜索引擎"对网站容量,质量的评估值,"扁平化,转静态 ..." |