Needless to say, this behavior of C and C++ programs opens the door
for many many ways of abusing the system.
You may have heard buffer overflows, which exploit precisely this flaw in C and C++
where people not only read but write beyond the elements of an array
in order to supplant malicious code and select locations of the memory.
This opens the door for all sorts of interesting hacks, of course.
How can one detect such errors?
What we need is a system invariant that continuously
checks the boundaries of an array against reads and writes.
What a tool can do for instance is constantly monitor the uninitialized areas
for reads and writes with every single instructions that is,
and whenever the program tries to access some system memory that is not allocated,
what will happen is that the invariant checker raises an exception or otherwise aborts the program
and therefore allows us to detect this kind of error.
Tools for C and C++ help you do that, include tools like electric fence,
which is precisely that, places these blocks in front and before every allocated block
and therefore detects when reads and writes happened outside of these allocated areas.
And the second important tool here is Valgrind, which actually is an interpreter for x86 binaries
in which also allows us to monitor accesses to non-initialized code for C and C++ programs.
Non c'e' bisogno di dire che questo comportamento dei programmi C e C++ apre le porte
a molti molti modi per abusare del sistema.
Avrai sentito parlare di buffer overflows, che sfruttano proprio questa falla del C e C++
in cui degli individui non solo possono leggere ma anche scrivere oltre gli elementi di un array
allo scopo di piazzare del codice dannoso e accedere a zone di memoria.
Cio' apre le porte a tutta una serie di hack interessanti, naturalmente.
Come ci si puo' accorgere di questi errori?
Cio' di cui abbiamo bisogno e' una invariante di sistema che controlli
continuamente che i confini di un array non vengano superati in lettura o scrittura.
Cio' che uno strumento potrebbe fare, per esempio, e' di monitorare costantemente le aree non inizializzate
in letture e scritture da qualsiasi singola istruzione che sia
e ogni qualvolta il programma tenti di accedere a della memoria di sistema non allocata,
succedera' che il controllore invariante sollevera' un eccezione oppure blocchera' il programma
consentendoci percio' di individuare questo tipo di errori.
Sono d'aiuto in questo degli strumenti per il C e C++, compresi strumenti come Electric Fence,
che e' esattamente questo: mette questi blocchi prima e dopo ogni blocco allocato
e percio' rileva quando delle letture e scritture avvengono al di fuori delle aree allocate.
E il secondo importante tool qui e' Valgrind, che e' proprio un interprete per binari x86
il quale ci consente di monitorare gli accesi al codice non inizializzato dei programmi C e C++.
言うまでもありませんが
このCとC++プログラムの動作が
システム乱用の原因となっています
バッファはCとC++の弱点で
不当に利用されることがあります
何者かが配列の要素を超えて
読み取りだけでなく書き込みを行い
悪意のあるコードに置き換え
メモリの場所を指定するのです
これがあらゆるハッカー行為へつながっています
このようなエラーを検出するには
読み取りと書き込みに反した配列の限度を
継続的にチェックするシステムの不変条件が必要です
例えばツールを利用すると命令1つで
読み取りと書き込みの未初期化領域を
絶えずモニタできます
割り当てられていないシステムメモリに
プログラムがアクセスしようとすると
不変条件チェッカが例外を発生させるか
プログラムを中止するのです
だからこのようなエラーを検出することができます
electric fenceのような
CとC++向けツールが役立つでしょう
割り当てられた全ブロックの前に
このようなブロックを適切に配置し
割り当てられた領域外で
読み取りや書き込みが行われると検出するのです
次に重要なツールがValgrindです
本来はX86バイナリ向けのインタープリタです
これを使うとCやC++プログラムの
未初期化コードへのアクセスをモニタできます
毋庸置疑,C/C++的这种做法打开一扇门,
形成了很多很多种系统崩溃的方式。
你可能听说过内存溢出,利用C/C++里的这个缺陷,
人们可以在数组范围之外进行读写,
恶意代码就是这样来获取内存位置的。
于是,这个就给各种黑客行为大开方便之门了。
那如何发现此类错误呢?
我们需要一个系统不变量来持续地
检查数组读写时的边界。
这里需要工具,来持续监控未初始化区域
的读写,监控每条指令语句的执行,
当程序试图访问一些未开辟的系统内存时,
不变量检查器就要抛出一个异常,或中止程序,
就能让我们检查到这类错误了。
C/C++的工具可以帮助你--包括像electric fence这些工具,
这种工具,将一些代码块放置在每个内存开辟的代码块前面,
检测是否有读取这些空间以外内存的操作。
其次重要的工具是Valgrind,它就是在x86平台下的一个解释器,
也允许我们来监控C/C++程序中的未初始化代码的访问情况。