Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I detect integer overflow flaws with valgrind?

Can I detect integer overflow flaws with valgrind? and which tool in it can do that?

like image 693
Syrena Avatar asked Dec 28 '12 08:12

Syrena


People also ask

Can Valgrind detect stack overflow?

In general, Valgrind detection of overflows in stack and global variables is weak to non-existant. Arguably, Valgrind is the wrong tool for that job. If you are on one of supported platforms, building with -fmudflap and linking with -lmudflap will give you much better results for these kinds of errors.

Does valgrind detect buffer overflow?

Valgrind won't detect buffer overflow.

How do you determine integer overflow?

Write a “C” function, int addOvf(int* result, int a, int b) If there is no overflow, the function places the resultant = sum a+b in “result” and returns 0. Otherwise it returns -1.

How do you know if overflow occurs?

The rules for detecting overflow in a two's complement sum are simple: If the sum of two positive numbers yields a negative result, the sum has overflowed. If the sum of two negative numbers yields a positive result, the sum has overflowed. Otherwise, the sum has not overflowed.


1 Answers

Valgrind has no tool which can detect integer overflow. You might maybe catch these bugs using the gcc option:

-ftrapv This option generates traps for signed overflow on addition, subtraction, multiplication
operations.
like image 112
phd Avatar answered Sep 19 '22 16:09

phd