剂量缓冲液溢出的原因 [英] why dosent buffer gets overflowed

查看:64
本文介绍了剂量缓冲液溢出的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< stdio.h>

#include< string.h>

#include< stdlib.h>

void func(char * p)

{

char i [5];

strcpy(i,p);

}


int main(int argc,char ** argv)

{


func(AAAAAAAAAA); //我已经提供了2 X 5字符

系统(暂停);

返回0;

}

解决方案

raashid bhatt说:


#include< stdio.h>

#include< string.h>

#include< stdlib.h>


void func(char * p )

{

char i [5];

strcpy(i,p);



主题行:为什么剂量缓冲区溢出


是什么让你觉得缓冲区不是溢出?


}


int main(int argc,char ** argv)

{$ / $

func(AAAAAAAAAA); //我已经为它提供了2个X 5字符



然后你试图在数组中存储的数据多于它的空间,

并且你没有提供任何保护措施,所以你会溢出

缓冲区,结果是程序展示未定义

行为 - 即C的规则不会告诉你会发生什么。


-

Richard Heathfield< http://www.cpax .org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日


8月21日,10:45 * pm,Richard Heathfield< r ... @ see.sig.invalidwrote:
< blockquote class =post_quotes>
raashid bhatt说:


#include< stdio.h>

#include< ; string.h>

#include< stdlib.h>


void func(char * p)

{

char i [5];

strcpy(i,p);



主题行:为什么剂量缓冲区溢出


是什么让你认为缓冲区不是溢出?


}


int main(int argc,char ** argv)

{


func(" AAAAAAAAAA"); //我已经为它提供了2个X 5字符



然后你试图在数组中存储的数据多于它有空间的数据,

并且你没有提供任何保护措施,所以你会溢出

缓冲区,结果是程序展示未定义

行为 - 即C的规则不会告诉你会发生什么。


-

Richard Heathfield< http://www.cpax .org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日



i我正在使用调试器来跟踪EIP,但是这个程序在nornally退出


raashid bhatt说:


8月21日晚上10点45分,Richard Heathfield< r ... @ see.sig.invalidwrote:


> raashid bhatt说:


#include< stdio.h>

#include< ; string.h>

#include< stdlib.h>


void func(char * p)

{

char i [5];

strcpy(i,p);


主题行:为什么剂量缓冲区溢出

是什么让你认为缓冲区没有溢出?


}


int main(int argc,char ** argv)

{


func(" AAAAAAAAAA"); //我已经为它提供了2个X 5字符


然后你试图在阵列中存储的数据多于它有空间的数据,
你不要不提供任何保护措施,所以你会溢出那个缓冲区,结果就是程序表现出不明确的行为 - 即C的规则不会告诉你会发生什么。



我正在使用调试器来跟踪EIP,但它的程序退出n



罚款。这是由于溢出来的原因导致的未定义行为的一个法律结果

缓冲区。规则中没有任何内容表明程序必须崩溃。


-

Richard Heathfield< http://www.cpax.org .uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日


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

void func(char *p)
{
char i[5];
strcpy(i, p);
}

int main(int argc, char **argv)
{

func("AAAAAAAAAA"); // i have supplied 2 X 5 char to it
system("pause");
return 0;
}

解决方案

raashid bhatt said:

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

void func(char *p)
{
char i[5];
strcpy(i, p);

Subject line: "why dosent buffer gets overflowed"

What makes you think the buffer isn''t being overflowed?

}

int main(int argc, char **argv)
{

func("AAAAAAAAAA"); // i have supplied 2 X 5 char to it

Then you''re trying to store more data in the array than it has room for,
and you don''t provide any safeguards against that, so you''re overflowing
that buffer, and the result is that the program exhibits undefined
behaviour - i.e. the rules of C don''t tell you what will happen.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


On Aug 21, 10:45*pm, Richard Heathfield <r...@see.sig.invalidwrote:

raashid bhatt said:

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

void func(char *p)
{
char i[5];
strcpy(i, p);


Subject line: "why dosent buffer gets overflowed"

What makes you think the buffer isn''t being overflowed?

}

int main(int argc, char **argv)
{

func("AAAAAAAAAA"); // i have supplied 2 X 5 char to it


Then you''re trying to store more data in the array than it has room for,
and you don''t provide any safeguards against that, so you''re overflowing
that buffer, and the result is that the program exhibits undefined
behaviour - i.e. the rules of C don''t tell you what will happen.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

i am using a debugger to track EIP but its this program exits nornally


raashid bhatt said:

On Aug 21, 10:45 pm, Richard Heathfield <r...@see.sig.invalidwrote:

>raashid bhatt said:

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

void func(char *p)
{
char i[5];
strcpy(i, p);


Subject line: "why dosent buffer gets overflowed"

What makes you think the buffer isn''t being overflowed?

}

int main(int argc, char **argv)
{

func("AAAAAAAAAA"); // i have supplied 2 X 5 char to it


Then you''re trying to store more data in the array than it has room for,
and you don''t provide any safeguards against that, so you''re overflowing
that buffer, and the result is that the program exhibits undefined
behaviour - i.e. the rules of C don''t tell you what will happen.


i am using a debugger to track EIP but its this program exits nornally

Fine. That''s one legal outcome of undefined behaviour caused by overflowing
a buffer. There''s nothing in the rules that says the program must crash.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


这篇关于剂量缓冲液溢出的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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