Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <limits.h>
- #include <stdio.h>
- #include <string.h>
- int main(int argc, char** argv)
- {
- unsigned short int test_int = 1234;
- char *test_str = "abcd";
- struct
- {
- char overflooded[3];
- unsigned short int overwritten;
- } overflow_size;
- memset(&overflow_size, 0, sizeof(overflow_size));
- overflow_size.overwritten = test_int;
- strcpy(overflow_size.overflooded , test_str);
- printf("We should get: %s, %hu\n", test_str, test_int);
- printf("We get: %s, %hu\n", overflow_size.overflooded, overflow_size.overwritten);
- struct
- {
- unsigned short int overflooded;
- char overwritten[4];
- } overflow_shift;
- memset(&overflow_shift, 0, sizeof(overflow_shift));
- unsigned short int *p_overflooded = &(overflow_shift.overflooded);
- p_overflooded++;
- strcpy(overflow_shift.overwritten, test_str);
- (*p_overflooded) = test_int;
- printf("We should get: %hu, %hu\n", test_int, test_int);
- printf("We get: %hu, %s\n", overflow_shift.overflooded, overflow_shift.overwritten);
- int i;
- struct
- {
- char * overflooded[2];
- unsigned short int overwritten[2];
- } overflow_bounds;
- memset(&overflow_bounds, 0, sizeof(overflow_bounds));
- for (i=0; i<=2; i++)
- overflow_bounds.overwritten[i] = test_int;
- for (i=0; i<=2; i++)
- overflow_bounds.overflooded[i] = test_str;
- printf("We should get:\n");
- for (i=0; i<=2; i++)
- printf(" %s, %hu\n", test_str, test_int);
- printf("We get:\n");
- for (i=0; i<=2; i++)
- printf(" %s, %hu\n", overflow_bounds.overflooded[i], overflow_bounds.overwritten[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement