SlideServe
Menu
Préférences
© SlideServe · v2026

11/2 실습

cher avatar
6 diapositives · 271 Views · Oct 09, 2014

11/2 실습. malloc ( ) 과 free() realloc () 과 _expand(); structure 와 union packed 와 padding Buffer overflow. Code example # 1 : Sizeof (A). // 소스 전체에 적용할 때는 # pragma pack(1) typedef struct __ attribute__((packed)) { int i; char c; } A; typedef struct { int i; char c;

11/2 실습 - slide 1
01 / 611/2 실습
1 / 17

Télécharger la présentation

11/2 실습
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. 11/2 실습

  2. malloc( ) 과 free() • realloc()과 _expand(); • structure 와 union • packed 와 padding • Buffer overflow

  3. Codeexample #1 : Sizeof(A) //소스 전체에 적용할 때는 #pragmapack(1) typedefstruct__attribute__((packed)) { inti; char c; } A; typedefstruct { inti; char c; } B; int main(intargc, char *args[]) { A a; B b; printf("%d \n", sizeof(a)); printf("%d \n", sizeof(b)); } typedefstructure{ inti; char c; } A; visual studio에서 옵션보기 : 프로젝트속성 C/C++  코드생성  구조체멤버맞춤 기타 경고수준 설정하여 컴파일하기

  4. Codeexample #2 unsigned float2bit(float f) { arg.f = f; printf("arg.u : %x \n",arg.u); printf("arg.f : %f \n",arg.f); returnarg.u; } int main() { //4.0의 floating point format = 0x40800000 unsigned i= 0x40800000; float f= 4.0; printf(" %f \n", bit2float(i)); printf(" %x \n",float2bit(f)); } #include<stdio.h> typedefunion { float f; unsigned u; } bit_float_t; bit_float_targ; float bit2float(unsigned u) { arg.u = u; printf("arg.u : %x \n",arg.u); printf("arg.f : %f \n",arg.f); returnarg.f; }

  5. Codeexample #3 : buffer overflow 리눅스와 Visual 환경에서 모두 테스트해 보도록 하세요 Visual 환경에서는 메모리도 함께 보세요. 내용을 확인한 사람은, intmy_gets(char *str, int n);를 만듭니다. 기능: str사이즈만큼만 입력받는다. 사이즈가 초과하면 -1을 return한다. #include<stdio.h> int main() { char test[4]="1"; charbuf[4]="0"; /* Way too small! */ charstr[4]=“”; printf(" input string \n"); scanf("%s",str); printf(" str: %s",str); fflush(stdin); //했을 때와 안했을 때의 차이 확인하세요. printf("Type a string: "); gets(buf); //입력값 puts(buf); //결과값 puts(test); //확인하세요 }

  6. Codeexample #4 : buffer overflow #include <stdio.h> void fn1(char *str){ char local[4]; printf(" == this is fn1 %s\n",str); strcpy(local, str); printf(" == strcpy to 'local : %s\n",local); } void fn2() { printf(" == this is fn2 \n"); printf(" == if you see this, stack overflow has been executed \n"); } int main(intargc, char *args[]) { printf("address of fn1 : 0x%x \n",fn1); printf("address of fn2 : 0x%x \n",fn2); printf("address of main : 0x%x \n",main); fn1(args[1]); }