Created
June 27, 2012 03:38
-
-
Save mshroyer/3001231 to your computer and use it in GitHub Desktop.
Uninitialized bool mischief
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 characters
| .file "bool1.c" | |
| .intel_syntax noprefix | |
| .section .rodata | |
| .LC0: | |
| .string "p is true" | |
| .LC1: | |
| .string "p is not true" | |
| .LC2: | |
| .string "p is false" | |
| .LC3: | |
| .string "p is not false" | |
| .text | |
| .globl main | |
| .type main, @function | |
| main: | |
| .LFB0: | |
| push rbp | |
| .LCFI0: | |
| mov rbp, rsp | |
| .LCFI1: | |
| sub rsp, 32 | |
| .LCFI2: | |
| mov DWORD PTR [rbp-20], edi | |
| mov QWORD PTR [rbp-32], rsi | |
| movzx eax, BYTE PTR [rbp-1] | |
| test al, al | |
| je .L2 | |
| mov edi, OFFSET FLAT:.LC0 | |
| call puts | |
| jmp .L3 | |
| .L2: | |
| mov edi, OFFSET FLAT:.LC1 | |
| call puts | |
| .L3: | |
| movzx eax, BYTE PTR [rbp-1] | |
| xor eax, 1 | |
| test al, al | |
| je .L4 | |
| mov edi, OFFSET FLAT:.LC2 | |
| call puts | |
| jmp .L5 | |
| .L4: | |
| mov edi, OFFSET FLAT:.LC3 | |
| call puts | |
| .L5: | |
| mov eax, 0 | |
| leave | |
| .LCFI3: | |
| ret |
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 characters
| #include <stdio.h> | |
| #include <stdbool.h> | |
| int main(int argc, char *argv[]) | |
| { | |
| volatile bool p; | |
| if ( p ) | |
| puts("p is true"); | |
| else | |
| puts("p is not true"); | |
| if ( ! p ) | |
| puts("p is false"); | |
| else | |
| puts("p is not false"); | |
| return 0; | |
| } |
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 characters
| .file "bool1.c" | |
| .intel_syntax noprefix | |
| .section .rodata.str1.1,"aMS",@progbits,1 | |
| .LC0: | |
| .string "p is true" | |
| .LC1: | |
| .string "p is not true" | |
| .LC2: | |
| .string "p is false" | |
| .LC3: | |
| .string "p is not false" | |
| .section .text.startup,"ax",@progbits | |
| .p2align 4,,15 | |
| .globl main | |
| .type main, @function | |
| main: | |
| .LFB22: | |
| sub rsp, 24 | |
| .LCFI0: | |
| movzx eax, BYTE PTR [rsp+15] | |
| test al, al | |
| je .L2 | |
| mov edi, OFFSET FLAT:.LC0 | |
| call puts | |
| .L3: | |
| movzx eax, BYTE PTR [rsp+15] | |
| test al, al | |
| je .L7 | |
| mov edi, OFFSET FLAT:.LC3 | |
| call puts | |
| .L5: | |
| xor eax, eax | |
| add rsp, 24 | |
| .LCFI1: | |
| ret |
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 characters
| #include <stdio.h> | |
| #include <stdbool.h> | |
| void fuzz() | |
| { | |
| volatile unsigned char x = 0x55; | |
| } | |
| void bool_test() | |
| { | |
| volatile bool p; | |
| if ( p ) | |
| puts("p is true"); | |
| else | |
| puts("p is not true"); | |
| if ( ! p ) | |
| puts("p is false"); | |
| else | |
| puts("p is not false"); | |
| } | |
| int main(int argc, char *argv[]) | |
| { | |
| fuzz(); | |
| bool_test(); | |
| return 0; | |
| } |
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 characters
| movzx eax, BYTE PTR c[rip] | |
| test al, al | |
| setne al | |
| mov BYTE PTR p[rip], al |
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 characters
| #include <stdbool.h> | |
| volatile char c = 0xff; | |
| volatile bool p; | |
| int main(int argc, char* argv[]) | |
| { | |
| p = (bool)c; | |
| return 0; | |
| } |
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 characters
| bool p; | |
| /* ... */ | |
| if ( p ) | |
| puts("p is true"); | |
| if ( ! p ) | |
| puts("p is false"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment