나는 최근에 위험한 프로그램을 이용하여 x86-64 아키텍처에서 gcc
버전의 차이점에 대해 흥미로운 것을 발견했습니다.gcc 버전 4.9.0 이상 gcc 버전 4.9 미만에서이 개선의 원인 및 이점?
주 : gets
의
부당한 사용은 여기 하지 문제입니다.
gets
을 다른 기능으로 바꾸면 문제가 변경되지 않습니다.#include <stdio.h> int main() { char buf[16]; gets(buf); return 0; }
내가 플래그
-m32 -fno-stack-protector -z execstack -g
와 함께 프로그램을 분해 gcc.godbolt.org를 사용
이은 내가 사용하는 소스 코드입니다. 버전으로 디스 어셈블 된 코드에서
,gcc
> =
4.9.0 :
lea ecx, [esp+4] # begin of main
and esp, -16
push DWORD PTR [ecx-4] # push esp
push ebp
mov ebp, esp
/* between these comment is not related to the question
push ecx
sub esp, 20
sub esp, 12
lea eax, [ebp-24]
push eax
call gets
add esp, 16
mov eax, 0
*/
mov ebp, esp
mov ecx, DWORD PTR [ebp-4] # ecx = saved esp
leave
lea esp, [ecx-4]
ret # end of main
그러나 GCC < 4.9.0 단지 버전 :
push ebp # begin of main
mov ebp, esp
/* between these comment is not related to the question
and esp, -16
sub esp, 32
lea eax, [esp+16]
mov DWORD PTR [esp], eax
call gets
mov eax, 0
*/
leave
ret # end of main
제 질문은 : 카우 (cau) 란 무엇입니까? 해체 된 코드와 그 이점에 대한이 차이점은? 이 기법의 이름이 있습니까?
참고 : [gets()'사용하지 마십시오. 위험합니다.] (http://stackoverflow.com/q/1694036/2173917). ['fgets()'] (https://linux.die.net/man/3/fgets)를 대신 사용하십시오. –
이것은 최적화 결과입니다 –
다른 컴파일러 구성입니다. 'gcc -v'를 사용하여 설정을 비교하십시오 – LPs