Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- const unsigned char input[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00,
- };
- static unsigned char *buf1 = NULL;
- static unsigned char *buf2 = NULL;
- static int test(void)
- {
- free(buf1);
- buf1 = malloc(sizeof(input));
- if (!buf1) { printf("malloc() failure\n"); exit(1); }
- memcpy(buf1, input, sizeof(input));
- free(buf2);
- buf2 = malloc(sizeof(input));
- if (!buf2) { printf("malloc() failure\n"); exit(1); }
- memcpy(buf2, input, sizeof(input));
- if (memcmp(buf1, buf2, sizeof(input)) != 0) {
- printf("MEMORY CORRUPTION???\n\n");
- printf("ORIG MEMORY:");
- for (size_t i = 0; i < sizeof(input); i++) {
- if (i % 24 == 0) printf("\n");
- printf("%02hhx ", buf1[i]);
- }
- printf("\n\nNEW MEMORY (different bytes suffixed with !):");
- for (size_t i = 0; i < sizeof(input); i++) {
- if (i % 24 == 0) printf("\n");
- printf("%02hhx%c", buf2[i], buf2[i] == buf1[i] ? ' ' : '!');
- }
- printf("\n\nCORRUPTED ADDRESS: old=%p+165{%02hhx} new=%p+165{%02hhx}\n\n",
- buf1, buf1[165], buf2, buf2[165]);
- return 0;
- }
- return 1;
- }
- int main(int argc, char **argv)
- {
- int runs = 0;
- int ok = 1;
- for (;;) {
- runs++;
- ok = test();
- if (!ok || runs >= 1000000) {
- printf("%s after %d runs\n",
- ok ? "Completed" : "Failure",
- runs);
- break;
- }
- }
- return !ok;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement