Example of unsafe program for Stack Frames

Source: Internet
Author: User

Example of unsafe program for Stack Frames
Stack frame description

Stack: the space where call records and parameters must be recorded when the C language program is running.

Save item:

Function tuning framework

Parameter transfer

Save returned values

Provide local variables

The story of an old driver driving by changing the stack frame
# Include <stdio. h> # include <stdlib. h> # include <string. h> # include <errno. h> void Exit () {printf ("I am a big bug, old driver \ n "); /// the old driver calls the shell command to drive a car. // there are many things that can be done here, such as // reading user privacy files and sending them over the network. // Modify the system, configure the system, delete files, and so on. system ("sl"); exit (10010);} void func (int x, int y) {int * p = & x; -- p; printf ("int Func \ n"); // The core action is here, by modifying the position where the returned value is saved in the stack frame, so that the function does not return normally, but enters the working position of the old driver. * P = Exit;} int main () {func (a, B); // The program is not running here printf ("after func () \ n "); return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.