NVIDIA Interview Question
InternsCountry: United States
Interview Type: Phone Interview
The related problem is about format strings. If the user can control de string used as first argument of printf() could dump memory regions or even execute arbitrary code.
Actually, when we assigns
char * s= "Hello".
's' starts pointing in read only segement where the "Hello" is.And when you do printf(s), IMO printf alwyas sees first argument as format string which it can change. And as he tries to change or format that argument you will get an access vilolation as you are writing to read only segment.
Answer based on http://stackoverflow.com/questions/4419293/warning-format-not-a-string-literal-and-no-format-arguments
Here, you are taking a string generated at runtime and trying to print it. Say for s is "bad%sdata" then the runtime will try to access a non-existent argument to match the %s. This will cause program to crash.
You can find an answer to this question in stack overflow with this topic/heading- warning: format not a string literal and no format arguments
- San January 15, 2014