프로그램 TEST 중 아래와 같은 오류가 발생했다.

결과는 Core dump.

jonathan@jonathan-laptop:~/workspace/TEST$ ./TEST
*** stack smashing detected ***: ./TEST terminated
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x50)[0xb775c390]
/lib/tls/i686/cmov/libc.so.6(+0xe233a)[0xb775c33a]
./TEST[0x804a2f4]
./TEST[0x8049189]
./TEST[0x8049258]
./TEST[0x8049205]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xb7690bd6]
./TEST[0x8049081]
======= Memory map: ========
08048000-0804f000 r-xp 00000000 08:05 7344439    /home/jonathan/workspace/TEST/TEST
0804f000-08050000 r–p 00007000 08:05 7344439    /home/jonathan/workspace/TEST/TEST
08050000-08051000 rw-p 00008000 08:05 7344439    /home/jonathan/workspace/TEST/TEST
08051000-080fd000 rw-p 00000000 00:00 0
09a2c000-09a4d000 rw-p 00000000 00:00 0          [heap]
b763d000-b765a000 r-xp 00000000 08:05 4849747    /lib/libgcc_s.so.1
b765a000-b765b000 r–p 0001c000 08:05 4849747    /lib/libgcc_s.so.1
b765b000-b765c000 rw-p 0001d000 08:05 4849747    /lib/libgcc_s.so.1
b7678000-b767a000 rw-p 00000000 00:00 0
b767a000-b77cd000 r-xp 00000000 08:05 4984558    /lib/tls/i686/cmov/libc-2.11.1.so
b77cd000-b77ce000 —p 00153000 08:05 4984558    /lib/tls/i686/cmov/libc-2.11.1.so
b77ce000-b77d0000 r–p 00153000 08:05 4984558    /lib/tls/i686/cmov/libc-2.11.1.so
b77d0000-b77d1000 rw-p 00155000 08:05 4984558    /lib/tls/i686/cmov/libc-2.11.1.so
b77d1000-b77d4000 rw-p 00000000 00:00 0
b77ef000-b77f2000 rw-p 00000000 00:00 0
b77f2000-b77f3000 r-xp 00000000 00:00 0          [vdso]
b77f3000-b780e000 r-xp 00000000 08:05 4855235    /lib/ld-2.11.1.so
b780e000-b780f000 r–p 0001a000 08:05 4855235    /lib/ld-2.11.1.so
b780f000-b7810000 rw-p 0001b000 08:05 4855235    /lib/ld-2.11.1.so
bff3e000-bff53000 rw-p 00000000 00:00 0          [stack]
Aborted (core dumped)

원인 분석을 위해 코어 파일과 함께 gdb를 실행 시켜 보았다.

jonathan@jonathan-laptop:~/workspace/TEST$ gdb -c core TEST
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type “show copying”
and “show warranty” for details.
This GDB was configured as “i486-linux-gnu”.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>…
Reading symbols from /home/jonathan/workspace/TEST/TEST…done.
[New Thread 5966]

warning: Can’t read pathname for load map: Input/output error.
Reading symbols from /lib/tls/i686/cmov/libc.so.6…(no debugging symbols found)…done.
Loaded symbols for /lib/tls/i686/cmov/libc.so.6
Reading symbols from /lib/ld-linux.so.2…(no debugging symbols found)…done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /lib/libgcc_s.so.1…Reading symbols from /usr/lib/debug/lib/libgcc_s.so.1…done.
done.
Loaded symbols for /lib/libgcc_s.so.1
Core was generated by `./TEST’.
Program terminated with signal 6, Aborted.
#0  0xb77f2430 in __kernel_vsyscall ()
(gdb) where
#0  0xb77f2430 in __kernel_vsyscall ()
#1  0xb76a4651 in raise () from /lib/tls/i686/cmov/libc.so.6
#2  0xb76a7a82 in abort () from /lib/tls/i686/cmov/libc.so.6
#3  0xb76db49d in ?? () from /lib/tls/i686/cmov/libc.so.6
#4  0xb775c390 in __fortify_fail () from /lib/tls/i686/cmov/libc.so.6
#5  0xb775c33a in __stack_chk_fail () from /lib/tls/i686/cmov/libc.so.6
#6  0x0804a2f4 in TestHeadMake () at test.c:515
#7  0x08049189 in TestLog (loglvl=1, title=0x804df59 “TEST”, fmt=0x804df57 “n”) at test.c:196
#8  0x08049258 in StartMessage () at test.c:237
#9  0x08049205 in main (argc=1, argv=0xbff509a4) at test.c:218

문제는 간단했다.

함수 TestHeadMake() 내에서 사용하는 문자열 버퍼 timeStr 의 사이즈가 데이터를 담기에 작았던 것.

바로 찾아서 해결을… 했으면 좋았겠지만 한참을 찾았다…;;

Tags: , , , , ,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.