スタックオーバーフロー

"DEBUG HACKS"記載のスタックオーバーフロー事例の追試結果を示す。

 

 

       
  • sum.cを準備する(ソースは参考文献の"DEBUG HACKS"を確認のこと)
  •    
  • コンパイルする      
    $ make sum
    cc     sum.c   -o sum

     
  •  

  • 実行する
       
    $ uname -a
    Linux localhost.localdomain 2.6.18-53.el5PAE #1 SMP Wed Oct 10 16:48:18 EDT 2007 i686 athlon i386 GNU/Linux $ ulimit -c unlimited
    $ ./sum
    セグメンテーション違反です (core dumped)
    $ ls core*
    core.16163

     
  •  

  • gdbで読み込む
       
    $ gdb -c core.16163
    ...
    Program terminated with signal 11, Segmentation fault.
    #0  0x08048454 in ?? ()
    (gdb) p $sp
    $1 = (void *) 0xbf3c0000
    (gdb) info files
    Local core dump file:
            `/home/nekonoshin/proc/sum/core.16163', file type elf32-i386.
            0x00314000 - 0x00315000 is load1
            0x008f4000 - 0x008f5000 is load3
            0x008f5000 - 0x008f6000 is load4
            0x00a32000 - 0x00a34000 is load6
            0x00a34000 - 0x00a35000 is load7
            0x00a35000 - 0x00a38000 is load8
            0x08049000 - 0x0804a000 is load10
            0xb7fef000 - 0xb7ff1000 is load11
            0xbf3c0000 - 0xbffc0000 is load12
    (gdb)

     

load12(stack領域のダンプ)が0xbf3c0000 - 0xbffc0000。スタックポインター($sp)の値、0xbf3c0000はstack領域の範囲外。

参考文献

     
  • DEBUG HACKS, P.53, "HACK#9 デバッグに必要なスタックの基礎知識"吉岡弘隆, 大和一洋, 大岩尚宏, 安部東洋, 吉田俊輔, 株式会社オライリー・ジャパン, ISBN978-4-87311-4040    

コメント