Fail-Safe Cを試してみた。
Fedora5にインストール。結構大変。Perlとか他にもいろいろ必要。
% yum install ocaml % yum install gdbm-devel % yum install camlp4 % yum install gc-devel % wget http://download.camlcity.org/download/findlib-1.2.1.tar.gz % ./configure && make && make install % wget http://ocaml-extlib.googlecode.com/files/extlib-1.5.1.tar.gz % sudo ocaml install.ml 3- Both Native and Bytecode installation
extlibは1~3でどれをインストールするか選択できるのだが最初1を選んだらうまくいかず入れ直そうとしたところ、もうインストールされている、となってしまったので削除。
sudo ocamlfind remove extlib
DebianにはパッケージでOcaml系もすべて用意されているようだが、Fedoraはなかなか面倒だった。本体にconfigureがないせいもあって手作業で修正も必要。
まず、/usr/include/gdbm/ndbm.h
がないと怒られる。
メモリ操作の安全性を確保する、ANSI C規格準拠C言語コンパイラ
このスラドのコメントが役に立った。
make clean
しないとエラーメッセージが変わってしまうので注意。
makeが通っても実行時にエラー。
/bin/sh: /usr/local/lib/fsc/default/compiler/../tools/read-elf-section: /usr/local/bin/perl: bad interpreter: No such file or directory
ちょっと無理矢理だが
ln -s /usr/bin/perl /usr/local/bin/perl
で解決。
さて。
わざと落ちそうなCのコードを用意してみる。
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char buf[10];
strcpy(buf, argv[1]);
printf("buf: %s\n", buf);
return 0;
}
% gcc -Wall hello.c % ./a.out hogehogehoge
とかやると
buf: hogehogehoge zsh: segmentation fault ./a.out hogehogehoge
こんな感じ。
fsccでコンパイルしたものを実行すると
% fscc -o hello hello.c % ./hello hogehogehoge
--------------------------------
Fail-Safe C trap: access out of bounds
Address: 0x896ed80 + 10
Cast Flag: not set
Region's type: char (VS 1, RS 1)
size: 10 (FA 10, ST 10)
block status: normal, no_user_dealloc
backtrace of instrumented code:
./hello[0x8052ae7]
./hello[0x8052de5]
./hello[0x8050e9b]
./hello[0x804d56c]
./hello[0x804b332]
./hello[0x804b474]
./hello[0x804b7fb]
/lib/libc.so.6(__libc_start_main+0xdc)[0x4b4c94e4]
./hello[0x8048e11]
(9 entries)
--------------------------------
zsh: abort ./hello hogehogehoge
こうなる。何に使えるかなぁ。

Fail-Safe CをFedoraにインストールしたときのメモ
コメントはまだありません。
»
コメントはお気軽にどうぞ



