Krista's Coding Corner

16.03.2012

Segmentation fault / Null pointer exception

Segmentation fault or in some languages Null pointer exception, also shown as “illegal operation” / “access violation” in some older Windows’s, are dangerous. Really. These are the main causes for our security holes.

If you get this one, it means that your programs is trying to touch (read or write) to the part of memory that it has no access. Or the program is trying to use resources that don’t belong to it, like writing into a file that is not open (to write into a file, you must always open it first in the program. Just like you can’t walk into a house if you don’t open the door). Specially, if you are using tables, it is easy to do something that you shouldn’t do. Always in these cases check that your lists are made correctly and you put values in them correctly.

Security hole, are you serious? Well, you only get the error we are speaking of if your operating system notices this error (or you are using some nice editor that also does your laundry while you take a nap). Some cases the operating system doesn’t notice these. Then it also won’t stop you (or anyone else!) doing anything stupid because it doesn’t know about your dump intentions. This means that the program can go and poke your computer as it wishes, no boundaries. Some nasty people can then use this to take control of your computer.

(Okay, if it is your own program and no one else has it, so no problem but in widespread programs we see an issue).

blog comments powered by Disqus