问题描述
我在这个问题上的认识不足表示歉意,但对我来说是非常重要的,所以至少我会试试看。
我使用的Windows 7旗舰版的Visual Studio 2012的前preSS,
我已经写了一些很基本的一个愚蠢的计划,以实践在C语言结构。不幸的是,我写的方法之一,有一个错误的条件停下来,它进入一个无限循环,它超过给定的数组边界的差了一截。我将添加code以下但在code不是我最关心的寿,我设法已经修复它,我只是想知道如果我能伤害我的系统还是我的个人文件(视频,照片,办公文件等)给定的方法,因为当我试图运行此code,一个可怕的事情发生了,我的电脑开始哔不休每0.5秒,我便无法做什么能阻止的是,程序是在无限循环并且我设法阻止这种乐趣只使用Ctrl + Alt + Del键,我写了codeS之前崩溃很多次,但I'ts确保在第一时间我的电脑strated声蜂鸣声。我希望专家能帮助我在这一个。非常感谢。
在无限循环,导致所有的问题的方法是printArrHero
#包括LT&;&stdio.h中GT;
#包括LT&;&string.h中GT;
结构日期{ INT日,月,年;}的typedef date_s;结构超级英雄{ CHAR名称[30]; 双动力,速度快; date_s生日;}的typedef sp_s;
无效printInfo(sp_s英雄){ 的printf(超级英雄信息:\\ n名称:[%S] \\ n,hero.name); 的printf(电源:[%.2lf] \\ n,hero.power); 的printf(速度:[%.2lf] \\ n,hero.speed); 的printf(生日:[%D /%D /%D]。\\ n \\ n,hero.birthday.day,hero.birthday.month,hero.birthday.year);}
无效addHero(ARR sp_s [],INT * K,sp_s newHero){ ARR [* K] = newHero;
(* K)++;
的printf(!\\ nSuccess一个新的超级英雄添加\\ n);
}无效printArrHero(ARR sp_s []){ INT J = 0; 而(ARR [J]!= NULL){ 输出([#%d个]≥>>>>>>>>>>>>>>>>> \\ N,J + 1); (ARR [J])printInfo; J ++;
}
}无效的主要(){ sp_s myHeros [100];
sp_s newHero; INT I = -1;
INT K = 0; 而(ⅰ!= 0){//菜单循环
的printf(欢迎到我的游戏\\ n);
的printf(添加英雄preSS 1 \\ n);
输出(要找到你最强的英雄preSS 2 \\ n);
输出(要找到你最快的英雄preSS 3 \\ n);
的printf(可以看到所有你英雄榜4的\\ n);
的printf(退出preSS 0 \\ n);
scanf函数(%d个,&安培; I) 开关(ⅰ){
情况下0:
打破; 情况1:
的printf(请输入#%d个英雄特点:\\ n名称:中,k + 1);
scanf函数(%S,&安培; newHero.name);
的printf(电源);
scanf函数(%LF,&安培; newHero.power);
的printf(速度);
scanf函数(%LF,&安培; newHero.speed);
的printf(出生日期[XX / XX / XX](格式):);
scanf函数(%D /%D /%D,&安培; newHero.birthday.day,&安培; newHero.birthday.month,&安培; newHero.birthday.year); addHero(myHeros,&安培; K,newHero); //现在,当我collecten做一个新的英雄所需要的所有信息可以发送到FUNC谓把它在#K地方数组中
打破; 案例2: 打破;
案例3: 打破; 情况4:
printArrHero(myHeros);
打破; } //开关的情况下END } //而菜单循环
} //主
Windows programs run in the context of the current user, and can perform any action of the current user. This means it could edit and delete your personal files.
Generally for a program to go rogue, it would need to have the activity within it. A program which deletes files, can more easily start accidentally deleting files.A program which edits files can make dodgy edits.
This is not a pre-requisite, as once it stops executing outside of your design, anything could happen.
For your system to be harmed, you would need to be running as administrator. That gives the program the ability to do any action which an adminstator could do, which could include serious damage to your machine.
There is one further stage, which is system
, which has complete control on the machine, more than an administator.
Is it likely?
Whilst it is possible, it is not very likely. The likelihood for modern programs is they crash before they corrupt files other than they are currently opening, however there are things which you can do to make the damage less-likely or more limited.
If you have significant files for your user, then consider switching to a different account for development. This would ring-fence the damage an errant program would cause.
Ensure you don't run with User-access-protection turned off. This limits your programs ability to administrate your machine.
- Consider an alternative platform, the
raspberry-pi
, or Intel compute stick offer a cheap platform which can be re-built if things go wrong.
Assuming it gets stuck in a loop, without properly reading data (probably scanf() returning 0).
The array gets filled up with all 100 elements, and then starts corrupting the stack.
There are 2 plausible memory layouts (windows x86/x86-64).
+---------+
| return |
| from |
| main |
+---------+
|hero[99] |
+---------+
|hero[98] |
+---------+
|hero[97] |
+---------+
| ... |
and
+---------+
| return |
| from |
| main |
+---------+
| k |
+---------+
|hero[99] |
+---------+
|hero[98] |
+---------+
|hero[97] |
+---------+
| ... |
In the first case, the array gets over-run, and the return address is modified. There is code built into normal compiles (security cookie), which would detect this, and the result is a crash before bad stuff happens.
In the second case, the memory for variable k gets overwritten with one of the array writes. This then sends k to some kooky place, and random memory is overwritten. This could corrupt the program data, but most likely the first attempt at non-natural k (outside of 0-99) would result in a crash.
The likely failure was that you printed out a control code such as a beep - that causes strange behavior, and is consistent with what you saw - I don't think anything bad happened for you.
这篇关于我不小心伤害系统文件或个人文件与Visual Studio 2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!