Issues with printf parameters

Source: Internet
Author: User

According to one of the previous articles, it is clear that for each function, the [ebp+x] of the function can directly access the value of the parameter passed in when it is called, and the local variable can be accessed directly by [Ebp-x].

So printf this function of the indefinite parameter implementation is implemented through the stack mechanism, when the actual parameter is passed, from the right to the left, the parameters are pressed into the stack, but the data of these presses into the stack is no type distinction, is to put the corresponding data into the stack in sequence. The last parameter, "%d%d%d", which is pressed into the stack, is what determines the type of printf parameter. When the execution control of the program arrives in printf, printf controls the type sequentially from the beginning of the passed-in argument, in the form of a string similar to "%d%d%d". This string controls the number and type of outputs. At the same time, this string does not cross detect.

int a = 10;printf ("%d%d%d\n", a);

This print out of bounds is not detected, the function calls the former argument stack a, and then presses the stack "%d%d%d\n" type control string. At the end of the function call in printf, three int is printed sequentially from the previously pressed argument, although the argument to the stack has only one int, but there is no out-of-bounds detection, so three int will be printed.

Issues with printf parameters

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.