Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribedimage text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Why is cybersecurity critical in smart grid infrastructure?

Answered: 1 week ago