Created
September 9, 2024 04:14
-
-
Save jmcph4/ad8aecdfc19084b3d05876fb2b04fb73 to your computer and use it in GitHub Desktop.
In case some of you have forgotten how computers work!
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 <stdlib.h> | |
| #include <stdint.h> | |
| int main(void) { | |
| uint8_t x = 0xca; | |
| uint8_t* p = &x; | |
| printf("x = %d p = %p\n", x, p); | |
| return EXIT_SUCCESS; | |
| } |
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 <stdlib.h> | |
| #include <stdint.h> | |
| #include <string.h> | |
| #define BUFLEN 8 /* 8 bytes */ | |
| #define CANARY 0x7F /* unlikely to receive this via `stdin` */ | |
| void foo(void) { | |
| printf("BANG!\n"); | |
| } | |
| int main(void) { | |
| uint8_t canary = CANARY; | |
| char buf[BUFLEN]; | |
| memset(buf, 0x00, BUFLEN); | |
| int res = scanf("%s", buf); | |
| if (res != EOF && res < 0) { | |
| perror("scanf"); | |
| return EXIT_FAILURE; | |
| } | |
| printf("%s\n", buf); | |
| printf("%d", canary); | |
| if (canary == CANARY) { | |
| printf(" (ok)\n"); | |
| } else { | |
| printf(" (bad)\n"); | |
| } | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment