Question: Code Given: #include #include #include /* * Program to illustrate data references that overrun intended bounds. * Compile this with gcc -m32 -g -o mystuff

Code Given:

#include #include #include /* * Program to illustrate data references that overrun intended bounds. * Compile this with gcc -m32 -g -o mystuff mystuff.c */ /* * Structure for holding my information. */ struct myData{ char public_info[20]; // publicly available stuff char fav_color[29]; int pin; // my pin int age; // my age }; /* * Initialize my information values. */ void setData(struct myData *data){ strcpy(data->public_info, "I yam what I yam."); strcpy(data->fav_color, "red"); data->pin = 99; data->age = 61; }

void showMemory(struct myData data){ /* temporary variables */ int offset; int result; /* Show memory values at offsets into the public data field */ while(1){ printf("Enter an offset into your public data and we'll show you the character value. (or q to quit) "); result = scanf("%d", &offset); if(result == 0){ break; } printf("Hex value at offset %d (address 0x%p) is 0x%x ", offset, &data.public_info[offset], data.public_info[offset]); } } void handleMyStuff(){ /* Declare myData variable my_data */ struct myData my_data;

/* Initialized my_data */ setData(&my_data);

/* Display address of my_data fields */ printf("Adress of public data:\t\t0x%p Address of secret PIN:\t\t0x%p ", &my_data.public_info[0], &my_data.pin); printf(" ");

/* Display values of my_data fields */ printf("Public data is %s ", my_data.public_info); printf("Hex value of PIN is 0x%x ", my_data.pin); printf(" "); showMemory(my_data); } int main(int argc, char *argv[]) { handleMyStuff(); printf(" Bye "); }

Results may vary, but review Example 1 and Answer the question:

Code Given:#include #include #include /* * Program to illustrate data references thatoverrun intended bounds. * Compile this with gcc -m32 -g -o mystuff

Address of public data: OxOxffc55d80 Address of secret PIN: OxOxffc55db4 Public data is I yam what I yam. Hex value of PIN is 0x63 Enter an offset into your public data and we'll show you the character value. (or q to quit)Address of public data: Oxoxffec08co Address of secret PIN: OxOxffec08f4 Public data is I yam what I yam. Hex value of PIN is 0x63 Enter an offset into your public data and we'll show you the character value

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!