Accessing invalid memory 

Another type of error is attempting to access memory that was never allocated. This is usually caused by the code attempting to dereference a null pointer, but it could also occur when a pointer is corrupt, as follows:

int main(void)
{
int *p = (int *)42;
*p = 0;
}

This results in the following output:

In the preceding example, we create a pointer to an integer and then provide it with a corrupt value of 42 (which is not a valid pointer). We then attempt to dereference the corrupt pointer, which results in a segmentation fault. It should be noted that the ASAN tool is capable of detecting this issue, but it is not capable of providing any useful information. This is because the ASAN tool is a library that hooks into memory allocation routines, keeping track of each allocation and how the allocations are used. If an allocation never occurs, it will not have any information about what happened above and beyond what a typical Unix signal handler could already provide, something that other dynamic analysis tools, such as Valgrind, are better suited to handle.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset