5 ms·
If the string was in a variable, yes, but in this case most implementations will put it in a RO section.
by temac 7y ago
If the string was in a variable, yes, but in this case most implementations will put it in a RO section.
- shakna 7y agoThat'll be depending on undefined behaviour, though, correct?
- simias 7y agoThat's not UB, that's implementation dependent, AFAIK the C standard says nothing about read-only memory. Attempting to modify a string literal is indeed UB but that would only happen if an attacker managed to attempt to modify the string, not when the program is used normally.
- shakna 7y ago> That's not UB, that's implementation dependent, AFAIK the C standard says nothing about read-only memory. If we're being pedantic, it's _unspecified behaviour_. The implementation isn't required to document how it would behave.
- shawnz 7y agoOther important security features like N^X are also not specified in the C standard either, so what's the point of worrying about just printf format strings?
- ryandrake 7y agoTBH it’s not pedantic to understand the difference between undefined, implementation-defined, and unspecified behavior. It’s part of knowing the language. One of my standard interview questions for C candidates is to ask them to describe and provide an example of each.
- Dylan16807 7y agoIs there really a meaningful difference between implementation-defined and unspecified? I'd say they're shades of gray based on how pedantic the compiler documentation is.
- temac 7y agoIs it really not UB to attempt to modify RO things? Typically (on major implementations, e.g. GNU/Linux or MSVC/Windows) it will crash, and I don't think it is allowed to crash on non-UB things?