Created
August 22, 2019 23:24
-
-
Save andermoran/aa219e345c806ccc4913cde0e2d7110a to your computer and use it in GitHub Desktop.
Revisions
-
andermoran created this gist
Aug 22, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ // https://twitter.com/zneakr/status/1164651753993715712 /* So @zneakr tweeted about this weird behavior and I decided to tinker with his example. In order to optimize, clang assigns fun_ptr to leak_all_my_secrets no matter what. This leads to "I have 9 toes" being printed no matter the result of the if statement. Super weird behavior from clang and I just wanted to make a note of it :) To reproduce this result: clang funkyClang.c -O1 -o funkyClang; ./funkyClang */ #include <stdlib.h> #include <stdio.h> static void (*fun_ptr)(void); void leak_all_my_secrets () { printf("I have 9 toes\n"); } int main() { if ((random() % 1000000) == 12321) { fun_ptr = leak_all_my_secrets; } fun_ptr(); }