Last active
December 1, 2024 09:03
-
-
Save pavly-gerges/069e14c16ab4f1c5d643f11ebe18094d to your computer and use it in GitHub Desktop.
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
// The following code examines multiple routines of definining dynamic buffers in C. | |
// This file fires a runtime malloc() error due to a HEAP corruption error; because of buffer overflow. | |
// Two maneuvers are introduced to fix this | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main() { | |
// buffers | |
const char *value1 = "Hi"; | |
const char *value2 = "Hello\n Dynamic Buffers!"; | |
// pointer to buffers | |
const char **inputs = malloc(sizeof(char *)); | |
// automatic allocation of address buffer ??? | |
// appends new addresses to the buffer automatically! | |
*inputs = value1; | |
*(inputs + 1) = value2; | |
*(inputs + 2) = value1; | |
*(inputs + 3) = value1; | |
*(inputs + 4) = value1; | |
// printf("%s\n", ((const char*) inputs[2])); | |
// printf("%s\n", ((const char*) inputs[2])); | |
free((void *) inputs); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following is a board summary to the 3 solutions presented here (incl. the defective solution that introduces memory access violations):
For more, follow the GNU Libc documentation for heap manipulating algorithms.