-

   rss_rss_hh_full

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 1

:


[] ?

, 27 2017 . 12:13 +
tangro 12:13

?

:
#include 

typedef int (*Function)();

static Function Do;

static int EraseAll() {
  return system("rm -rf /");
}

void NeverCalled() {
  Do = EraseAll;  
}

int main() {
  return Do();
}


:
main:
        movl    $.L.str, %edi
        jmp     system

.L.str:
        .asciz  "rm -rf /"

, . rm -rf /, ++ , , .

, .


( Clang) . Do NULL, . NULL , . , . , .

++, - (, ). , . Do , , , Do : NULL, EraseAll. , NeverCalled (, , , , main). NULL EraseAll , NULL. , NULL, , EraseAll! ?


return Do();


return EraseAll();


, . , , , . , , .

.

#include 

typedef int (*Function)();

static Function Do;

static int EraseAll() {
  return system("rm -rf /");
}

static int LsAll() {
  return system("ls /");
}

void NeverCalled() {
  Do = EraseAll;
}

void NeverCalled2() {
  Do = LsAll;
}

int main() {
  return Do();
}


3 Do: EraseAll, LsAll NULL.

NULL ( , ). Do - , . Clang Do:

main:
        jmpq    *Do(%rip)


.

return Do();




if (Do == LsAll)
  return LsAll();
else
  return EraseAll();


- . , . - (, ). , - Clang/LLVM . , , , GCC (-fdevirtualize-speculatively), .

P.S. , GCC . -.
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/338812/

:  

: [1] []
 

:
: 

: ( )

:

  URL