I atm can only think of three ways the program might 'mess up' like this:
- stack smashing/etc and shell code being used to execute arbitrary instructions by an attacker
- the program is trojanized
- the program actually was designed to do these things, so it's not really a problem (like 'rm' for example).
So, no, I don't think there is anything that prevents developers from doing this. But maybe I'm not understanding it completely ? (I'm guessing that's the case but I'll say a bit more anyway).
I can't think of any instance where a program would read/write files (thus having possibility to corrupt them) it does not actually need.
I suppose you could just have all paths relative to the program's data directory, but I don't see why or how what you're saying is a problem.
Could you provide an example ? I know in my projects I use the 'chdir' call to change to a data directory, and anything is relative to that directory I change to... thus if I open a file 'test' it'll be under that data directory (unless I specify something else like a full path).
If you do provide an example, I think it'd be easier to understand what you're saying ... but in general, a program shouldn't be touching files or configurations it doesn't use (there is no need to) by normal operation.
Looking at your post again, I see you mean if it messes up or is cracked. In the case of code being injected in to it, I can only think of a few things that would help prevent that.
Such things as PIE/SSP and PaX.
http://www.grsecurity.net/http://www.nsa.gov/selinux/http://pax.grsecurity.net/Basically, kernels and compilers/etc can be patched to prevent these kinds of attacks (as in stack smashing). I don't use these on my servers because they making my things rather difficult to develop (debugging comes to mind as a bother with these things implemented).
But see also:
http://www.gentoo.org/proj/en/hardened/primer.xmlfor some ideas on those things I mentioned (PaX, PIE, SSP etc).
If you still have questions, let me know and I'll get back to you soon (either later tonight or tomorrow - Wednesday).