4 ms·
It'll crash and potentially allow code execution if the rest of the args are user coercible. Check out the first few chapters of The Shellcoder's Handbook for e
by getsat 15y ago
It'll crash and potentially allow code execution if the rest of the args are user coercible. Check out the first few chapters of The Shellcoder's Handbook for examples.
Thanks for the explanation. I've never seen/had to use %d with integers. I've only used it with %.Nd for floats/doubles.
- irahul 15y agoLeaving it at "crash and don't do it" is enough for a beginner C book. Mentioning code execution and shell code isn't really in the scope. If he mentions code execution, then it sort of warrants mentioning modern architecture prevent executing data as code, or the code segment is not writable on many architectures...and shell code is basically the op code that your machine executes, and injecting shell code in absence of any protecting mechanism will execute arbitrary code, and in presence of protection mechanism, it will crash. I think just mentioning shell codes and code execution aren't doing a beginner any good. And explaining it is well out of scope. It's not that this is going to be the end all C book, and as long as the reader sticks to using proper format strings, he is good. If he doesn't, knowing about what might happen isn't doing much good either.
- getsat 15y ago> as the reader sticks to using proper format strings, he is good. Another important point to mention is that the format string itself should not be user coercible! XCode/LLVM/whatever Apple is using nowadays actually treats non-constant format strings as a compilation error, which is pretty cool.
- zedshaw 15y agocode/ex3.c:6: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘double’ You should probably read this book. :-)
- getsat 15y agoHmm, I don't recall MSVC++ ever warning about that! Unfortunately, I did use Windows at one point in my career. I'll pass on reading it since I don't intend to write C ever again, but I hope the book works out well for you. :) Edit: Just dug up some of my old C code. It is indeed %.2f that I was thinking of. Sorry for the confusion once again.