checker 0.9.9.1 review

Download
by rbytes.net on

checker can help find bugs that standard tools cannot always find

License: GPL (GNU General Public License)
File size: 545K
Developer: Tristan Gingold
0 stars award from rbytes.net

checker can help find bugs that standard tools cannot always find. The best example is memory leaks. A memory leak is a zone of memory, allocated with malloc that is not used anymore. So the memory allocated is lost.

This means you program needs more memory and runs slower, since your OS might have to start swapping. It detects bad memory accesses such as: reading uninitialized memory, writing in a freed zone, writing or reading outside of a memory block, and using NULL pointers. This is particularly useful for big programs with many functions.

Checker maintains bitmaps to keep track of the status of each byte of memory. The status can be writable, readable, both, or none. When memory is allocated, the new memory becomes write-only: you are not allowed to read it because it has not been initialized.

But when you you write to this new block, those bytes become readable and writable. When the block is freed, the bytes become unreadable and unwritable. Red zones are unreadable and unwritable memory, so that each access to a red zone produces a warning.

Example:

Here's a bogus file example.c:

#include < stdlib.h >

int
main ()
{
char *zone = malloc (20);
char *ptr = NULL;
int i;
char c;

c = zone[1]; /* error: read an uninitialized char */
c = zone[-2]; /* error: read before the zone */
zone[25] = ' '; /* error: write after the zone */
*ptr = 2; /* error: use a NULL pointer,
must produce a core */
}

To compile this example with Checker, simply use checkergcc instead of gcc:
% checkergcc -o example example.c

Next, to run the example:
% ./example

Execution produces these warnings:

Checker 0.9 (sparc-sun-solaris2.5.1) Copyright (C) 1998 Tristan Gingold.
Checker is a memory access detector.
Checker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
For more information, set CHECKEROPTS to `--help'
From Checker (pid:04713): `./example' is running (Sun Jan 18 14:56:49 1998)

From Checker (pid:04713): (ruh) read uninitialized byte(s) in a block.
When Reading 1 byte(s) at address 0x000398a1, inside the heap (sbrk).
1 bytes into a block (start: 0x398a0, length: 20, mdesc: 0x0).
The block was allocated from:
pc=0x00022f1c in chkr_malloc at ../stubs/stubs-malloc.c:51
pc=0x0001339c in main at ../example.c:7
pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
pc=0x00013298 in *unknown* at *unknown*:0
Stack frames are:
pc=0x000133f4 in main at ../example.c:12
pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
pc=0x00013298 in *unknown* at *unknown*:0
From Checker (pid:04713): (bvh) block bounds violation in the heap.
When Reading 1 byte(s) at address 0x0003989e, inside the heap (sbrk).
2 bytes before a block (start: 0x398a0, length: 20, mdesc: 0x0).
The block was allocated from:
pc=0x00022f1c in chkr_malloc at ../stubs/stubs-malloc.c:51
pc=0x0001339c in main at ../example.c:7
pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
pc=0x00013298 in *unknown* at *unknown*:0
Stack frames are:
pc=0x00013434 in main at ../example.c:13
pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
pc=0x00013298 in *unknown* at *unknown*:0
From Checker (pid:04713): (bvh) block bounds violation in the heap.
When Writing 1 byte(s) at address 0x000398b9, inside the heap (sbrk).
5 bytes after a block (start: 0x398a0, length: 20, mdesc: 0x0).
The block was allocated from:
pc=0x00022f1c in chkr_malloc at ../stubs/stubs-malloc.c:51
pc=0x0001339c in main at ../example.c:7
pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
pc=0x00013298 in *unknown* at *unknown*:0
Stack frames are:
pc=0x0001345c in main at ../example.c:14
pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
pc=0x00013298 in *unknown* at *unknown*:0
From Checker (pid:04713): (nza) null zone addressed.
When Writing 1 byte(s) at address 0x00000000, inside the NULL zone.
You probably deferenced a null pointer.
THIS SHOULD CAUSE A SEGMENTATION FAULT.
Stack frames are:
pc=0x0001347c in main at ../example.c:15
pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
pc=0x00013298 in *unknown* at *unknown*:0
From Checker (pid:04713): (sig) signal.
Receive signal 11 (SEGV): (default action: terminate core ).

Segmentation fault

checker 0.9.9.1 search tags