diff --git a/.gitattributes b/.gitattributes index 2e45f284a43724d4c641c4be8fe7b4efd3dae6d7..d47d7a93e69e2e3c2b380c11d7ea1c4caa73a132 100644 --- a/.gitattributes +++ b/.gitattributes @@ -307,6 +307,8 @@ libtransform/tests/int16overflow.c -text libtransform/tests/int32overflow.c -text libtransform/tests/mul.c -text libtransform/tests/sample_meds_int.annot -text +libtransform/tests/simpletest.c -text +libtransform/tests/unsigned_add.c -text tests/coreutils/Makefile -text tests/coreutils/bzip2_manual_tests.sh -text tests/coreutils/cat_manual_tests.sh -text diff --git a/libtransform/src/integertransform.cpp b/libtransform/src/integertransform.cpp index bdaee13e7aec04406605935826889a973db9c2f4..16f1052b7d615b8e1ddab83d6666dfddf0637118 100644 --- a/libtransform/src/integertransform.cpp +++ b/libtransform/src/integertransform.cpp @@ -82,7 +82,17 @@ void IntegerTransform::handleOverflowCheck(Instruction_t *p_instruction, const M addOverflowCheck(p_instruction, p_annotation); else if (p_annotation.getBitWidth() == 32) { - addOverflowCheck(p_instruction, p_annotation); + if (p_annotation.isUnderflow() || p_annotation.isOverflow()) + { + if (p_annotation.isSigned() || p_annotation.isUnsigned()) + { + addOverflowCheck(p_instruction, p_annotation); + } + else + { + cerr << "integertransform: unknown sign: do not instrument" << endl; + } + } } } @@ -216,7 +226,7 @@ void IntegerTransform::addOverflowCheck(Instruction_t *p_instruction, const MEDS cerr << "void IntegerTransform::addOverflowCheck(): enter: " << p_instruction->GetComment() << endl; assert(getVariantIR() && p_instruction); - string detector(TRUNCATION_DETECTOR); + string detector(INTEGER_OVERFLOW_DETECTOR); string dataBits; AddressID_t *jncond_a =new AddressID_t; @@ -298,6 +308,12 @@ cerr << "void IntegerTransform::addOverflowCheck(): enter: " << p_instruction->G detector = string(ADDSUB_OVERFLOW_DETECTOR_UNSIGNED_32); cerr << "integertransform: ADD/SUB OVERFLOW UNSIGNED 32" << endl; + } + else + { + cerr << "integertransform: ADD/SUB OVERFLOW UNKONWN 32: do nothing for now" << endl; + return; + } jncond_i->SetDataBits(dataBits); diff --git a/libtransform/tests/int32overflow.c b/libtransform/tests/int32overflow.c index 152d18eeb3f2f822fba615e53132ce04f21a1702..a23cb79da011dc376af81c623d772bddca834f91 100644 --- a/libtransform/tests/int32overflow.c +++ b/libtransform/tests/int32overflow.c @@ -3,10 +3,8 @@ int main(int argc, char **argv) { unsigned int x; - x = 0xFFFFFFFF; x++; - printf("Value of unsigned int (add): %u\n", x); unsigned int s; @@ -14,9 +12,16 @@ int main(int argc, char **argv) s--; printf("Value of unsigned int (sub): %u\n", s); +/* +overflow flag not set in this example! unsigned int m1 = 5; unsigned int m2 = 0xFFFFFFFF; m1 = m1 * m2; printf("Value of unsigned int (mul): %u\n", m1); +*/ + int m1 = 0x0FFFFFFF; + int m2 = 0x0FFFFFFF; + m1 = m1 * m2; + printf("Value of int (mul): %d\n", m1); } diff --git a/libtransform/tests/mul.c b/libtransform/tests/mul.c index 2b8adb3fa079b92fc2a08ba364c35d6eb29ec7b8..5b89a986294b1cbad45acc81e3737c36076e3846 100644 --- a/libtransform/tests/mul.c +++ b/libtransform/tests/mul.c @@ -4,8 +4,8 @@ int main(int argc, char **argv) unsigned a = (unsigned) atoi(argv[1]); unsigned b = (unsigned) atoi(argv[2]); unsigned d = a * b; - printf("%u * %u = %u\n", a, b, d); - printf("hello, how are you?"); + printf("%u\n", d); +// printf("%u * %u = %u\n", a, b, d); } diff --git a/libtransform/tests/simpletest.c b/libtransform/tests/simpletest.c new file mode 100644 index 0000000000000000000000000000000000000000..882990edf87e8f2df6b1285fc3832cae54beed2e --- /dev/null +++ b/libtransform/tests/simpletest.c @@ -0,0 +1,20 @@ +// from smartfuzz paper +// ./simpletest.exe -2147483659 will trigger the Surprise +int main (int argc, char** argv) +{ + int i = atol(argv[1]); + unsigned int j = 0; + + if (i < 10) + { + j = i; + if ( j > 50) + { + printf("Surprise! \n"); + return 1; + } + } + +return 0; + +} diff --git a/libtransform/tests/unsigned_add.c b/libtransform/tests/unsigned_add.c new file mode 100644 index 0000000000000000000000000000000000000000..465a9f55d62ed6c0017aaf8993c55c23098be997 --- /dev/null +++ b/libtransform/tests/unsigned_add.c @@ -0,0 +1,13 @@ +int main(int argc, char **argv) +{ + unsigned delta = 0xFFFFFFF0; + unsigned base = 0xFFFFFFF0; + unsigned result = delta; + + if (delta > 0) + delta++; + + result = base + delta; + + printf("%u + %u = %u\n", base, delta, result); +}