Skip to content

Instantly share code, notes, and snippets.

@jmcph4
Created September 9, 2024 04:14
Show Gist options
  • Select an option

  • Save jmcph4/ad8aecdfc19084b3d05876fb2b04fb73 to your computer and use it in GitHub Desktop.

Select an option

Save jmcph4/ad8aecdfc19084b3d05876fb2b04fb73 to your computer and use it in GitHub Desktop.
In case some of you have forgotten how computers work!
#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;
}
#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