What is the use of the %n format specifier in C?

Viewed 118419

What is the use of the %n format specifier in C? Could anyone explain with an example?

11 Answers

Those who want to use %n Format Specifier may want to look at this:

Do Not Use the "%n" Format String Specifier

In C, use of the "%n" format specification in printf() and sprintf() type functions can change memory values. Inappropriate design/implementation of these formats can lead to a vulnerability generated by changes in memory content. Many format vulnerabilities, particularly those with specifiers other than "%n", lead to traditional failures such as segmentation fault. The "%n" specifier has generated more damaging vulnerabilities. The "%n" vulnerabilities may have secondary impacts, since they can also be a significant consumer of computing and networking resources because large guantities of data may have to be transferred to generate the desired pointer value for the exploit. Avoid using the "%n" format specifier. Use other means to accomplish your purpose.

Source: link

Related