Question: I need these Secure Coding Questions in C PLEASE DO NOT COPY ANSWERS FROM CHEGG, BECAUSE THEY ARE WRONG In class, we gave a very

I need these Secure Coding Questions in C PLEASE DO NOT COPY ANSWERS FROM CHEGG, BECAUSE THEY ARE WRONG

In class, we gave a very basic macro design to implement stack guard with canary. In that design, we havent talk about how to define __SECRET_VAR in the macros. A simple way to define __SECRET_VAR is some marco like #define __SECRET_VAR 11223344 But the issue is that it is a constant so an attacker can know. A better strategy is to make it a variable and assign a random number to it at run time. You job is to write the entire set of macros in a head file mycanary.h so a users program can include the header file and use all macros for stack protection. You have already been given the following users code, which uses four macros: DEF_CANARY(), PLACE_CANARY(), SAFE_RETURN(), and INIT_CANARY(). Please complete all four macros in the header file mycanary.h so __SECRET_VAR can be assigned randomly at run time. Submit the content of your mycanary.h. Screen-shot the result to show your macros can successfully detect buffer overflow in the following code. (50pts) #include #include #include"mycanary.h" DEF_CANARY(); /* define canary as global*/ void vul_fun(char *str) { PLACE_CANARY(); /* place a canary */ char buf[16]; strcpy(buf, str); printf("buf=%s ", buf); SAFE_RETURN(); /* check canary and return */ } int main(){ INIT_CANARY(); /* randomize the value of canary */ vul_fun("123456789012345678901234567890"); } Hints: You can define a global variable in DEF_CANARY, then assign a random value (using random functions in C) to __SECRET_VAR in INIT_CANARY. PLACE_CANARY() and SAFE_RETURN() c

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 Databases Questions!