Sunday, July 12, 2009

In C++, how does an uninitialised pointer crash a system....??

Mark F's answer is very good and correct but as for how the uninitialized pointer can crash a system, not just a "process" running on a system, the short answer is it can't or it shouldn't be able to.


On a modern operating system that is not malfunctioning the reason a process "crashes" when trying to access memory it does not "own" is this "crash" is the operating system "protecting" itself from being corrupted by the illegal memory access via the uninitialized pointer (you may have heard of protected mode in x86 processors; this is what it's for).


That said, many of the security holes found by hackers in Microsoft Windows operating systems were exploits using pointers in to supposedly invalid memory that the operating system didn't properly detect. Some of these memory regions have access levels greater then the user space (application ring) and once a program is loaded into this type of memory it can corrupt the system and cause it to crash.

In C++, how does an uninitialised pointer crash a system....??
By itself, an uninitialized pointer is harmless. Try to use that pointer and your program will most likely crash, or at least not behave correctly because you are working with random data. Usually uninitialized pointers point to memory the application is not allowed to access, so the operating system says the program must shut down because it performed an illegal operation. It's rare that bad pointers will totally crash a system.
Reply:hii dear


u have a class in c++ in which there is a pointer . u had not created any constructor or created but not initialised the pointer in that constructor then a default value will be attached with your pointer and that is a NULL.u can say it a null reference .its not the real addres of machine's memory actually a null reference means it is pointing to nowhere .when u will try to use it it will throw an exception that it is a NULL reference it is pointing to nowhere or clearly saying it will say illegal address accessing at this stage the if u had installed any exception handler for this will be called.If u had not installed the exception handler then default exception handler of operating system will be called which due to security reason will close the application (or ur application crashes).I want to point one thing here ur application crashes not the system crashes.System will crash in that situation where u r working in kernel area and done something wrong.but normally we work in user so there is no chance(rare chance) for system crash.
Reply:The operating system works in conjunction with the hardware to keep track of which applications are allowed to use which parts of memory, and the way in which they're allowed to use it (i.e. data, code etc). An uninitialized pointer usually contains either a random value or the value 0, neither of which are likely to point to an area of memory that the task is allowed to use. Attempting to read from or write to this part of memory causes the CPU to automatically trigger a hardware interrupt which the operating system detects, it then "crashes" (i.e. terminates) the offending application as a precaution.


No comments:

Post a Comment