#include <stdio.h>
void wrapperPrint(char* s)
{
printf(s);
return;
}
int main()
{
wrapperPrint("Hello world\n");
wrapperPrint("This is a string");
return 0;
}
If the program prints strings correctly (it does, tested on gcc 4.6.3) , why do we need format specifiers like %d, %s etc. Or in other words, what is the potential problem with this program.
wrapperPrint("%s%s%s%s%s%s%s%s");. You can crash the process. you can read the process's memory footprint...`printfdoesn't know how many arguments were actually passed to it (nor the type of the arguments), so it'll callva_argfor each%sin the format string and retrieve a value from the stack. It treats each value as achar*and attempts to print each one. Your code above is susceptible to format string attacks.