Commit 6bc141c9 authored by Sergio Costas's avatar Sergio Costas

Removing "crust_disable" in the tests, to make them more secure

parent 498b69a9
......@@ -120,22 +120,22 @@ class Test(unittest.TestCase):
self._generic_test("unitest/test3.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param3", 7, 6) ])
def test004UseUninitialized(self):
self._generic_test("unitest/test4.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} isn't initialized", 1, "function", 5) ])
self._generic_test("unitest/test4.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} isn't initialized", 1, "function", 7) ])
def test005UseFreed(self):
self._generic_test("unitest/test5.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 6, 5) ])
def test006PassedNonCrustyToCrusty(self):
self._generic_test("unitest/test6.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust_t__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed non __crust_t__ variable", 1, "function", 6) ])
self._generic_test("unitest/test6.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust_t__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed non __crust_t__ variable", 1, "function", 8) ])
def test007PassedCrustyToNonCrusty(self):
self._generic_test("unitest/test7.c", [ (crust.crust.MSG_CRITICAL, "Expected a non __crust_t__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed a __crust_t__ variable", 1, "function", 6) ])
self._generic_test("unitest/test7.c", [ (crust.crust.MSG_CRITICAL, "Expected a non __crust_t__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed a __crust_t__ variable", 1, "function", 8) ])
def test008PassedOtherToCrusty(self):
self._generic_test("unitest/test8.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust_t__ variable as argument {:d} when calling function '{:s}' at line {:d}", 1, "function", 5) ])
self._generic_test("unitest/test8.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust_t__ variable as argument {:d} when calling function '{:s}' at line {:d}", 1, "function", 7) ])
def test009PassedIncorrectNumberOfParameters(self):
self._generic_test("unitest/test9.c", [ (crust.crust.MSG_CRITICAL, "Calling function '{:s}' at line {:d} with an incorrect number of arguments", "function", 5) ])
self._generic_test("unitest/test9.c", [ (crust.crust.MSG_CRITICAL, "Calling function '{:s}' at line {:d} with an incorrect number of arguments", "function", 7) ])
def test010NonExistingFunction(self):
self._raise_test("unitest/test10.c", crust.crust.FunctionNotFoundException, [ (crust.crust.MSG_CRITICAL, "Calling function '{:s}' at line {:d}, but it is not declared or defined", "function3", 5) ])
......@@ -174,7 +174,7 @@ class Test(unittest.TestCase):
self._generic_test("unitest/test21.c", [ (crust.crust.MSG_ERROR, "Using variable '{:s}' at line {:d}, after being freed at line {:d}", "param4", 8, 7) ])
def test022AssignFreedVariable(self):
self._generic_test("unitest/test22.c", [ (crust.crust.MSG_ERROR, "Using variable '{:s}' at line {:d}, after being freed at line {:d}", "param1", 5, 4) ])
self._generic_test("unitest/test22.c", [ (crust.crust.MSG_ERROR, "Using variable '{:s}' at line {:d}, after being freed at line {:d}", "param1", 5, 4), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param4", 4, 7) ])
def test023AssignUninitializedVariable(self):
self._generic_test("unitest/test23.c", [ (crust.crust.MSG_ERROR, "Using uninitialized variable '{:s}' at line {:d}", "param4", 5) ])
......@@ -186,31 +186,31 @@ class Test(unittest.TestCase):
self._generic_test("unitest/test25.c", [ (crust.crust.MSG_CRITICAL, "Assigning the crust variable '{:s}' to the non-crust variable '{:s}' at line {:d}", "param4", "param5", 5) ])
def test026TypeCast(self):
self._all_fine_test("unitest/test26.c")
self._generic_test("unitest/test26.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 6, 8) ])
def test027AssignNonCrustToCrust2(self):
self._generic_test("unitest/test27.c", [ (crust.crust.MSG_CRITICAL, "Assigning a non-crust value to the crust variable '{:s}' at line {:d}", "param", 5) ])
self._generic_test("unitest/test27.c", [ (crust.crust.MSG_CRITICAL, "Assigning a non-crust value to the crust variable '{:s}' at line {:d}", "param", 5), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 5, 7) ])
def test028CrustRetVal(self):
self._generic_test("unitest/test28.c", [ (crust.crust.MSG_ERROR, "Calling the function '{:s}' at line {:d}, but ignoring the crust-type return value", "function", 5) ])
self._generic_test("unitest/test28.c", [ (crust.crust.MSG_ERROR, "Calling the function '{:s}' at line {:d}, but ignoring the crust-type return value", "function", 7) ])
def test029UseUninitialized2(self):
self._generic_test("unitest/test29.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} isn't initialized", 1, "function", 5) ])
self._generic_test("unitest/test29.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} isn't initialized", 1, "function", 7) ])
def test030UseFreed2(self):
self._generic_test("unitest/test30.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 6, 5) ])
def test031PassedNonCrustyToCrusty2(self):
self._generic_test("unitest/test31.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust_t__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed non __crust_t__ variable", 1, "function", 6) ])
self._generic_test("unitest/test31.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust_t__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed non __crust_t__ variable", 1, "function", 8) ])
def test032PassedCrustyToNonCrusty2(self):
self._generic_test("unitest/test32.c", [ (crust.crust.MSG_CRITICAL, "Expected a non __crust_t__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed a __crust_t__ variable", 1, "function", 6) ])
def test033PassedOtherToCrusty2(self):
self._generic_test("unitest/test33.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust_t__ variable as argument {:d} when calling function '{:s}' at line {:d}", 1, "function", 5) ])
self._generic_test("unitest/test33.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust_t__ variable as argument {:d} when calling function '{:s}' at line {:d}", 1, "function", 6) ])
def test034MultiAssign(self):
self._generic_test("unitest/test34.c", [ (crust.crust.MSG_CRITICAL, "Assigning a non-crust value to the crust variable '{:s}' at line {:d}", "b", 6) ])
self._generic_test("unitest/test34.c", [ (crust.crust.MSG_CRITICAL, "Assigning a non-crust value to the crust variable '{:s}' at line {:d}", "b", 6), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "a", 6, 8)] )
def test035AmpPointer(self):
self._all_fine_test("unitest/test35.c")
......@@ -219,7 +219,7 @@ class Test(unittest.TestCase):
self._all_fine_test("unitest/test36.c")
def test037StructAssign(self):
self._generic_test("unitest/test37.c", [ (crust.crust.MSG_CRITICAL, "Assigning the non-crust variable '{:s}' to the crust variable '{:s}' at line {:d}", "test", "param4", 8) ])
self._generic_test("unitest/test37.c", [ (crust.crust.MSG_CRITICAL, "Assigning the non-crust variable '{:s}' to the crust variable '{:s}' at line {:d}", "test", "param4", 10) ])
def test038ArrayElement(self):
self._all_fine_test("unitest/test38.c")
......@@ -240,17 +240,19 @@ class Test(unittest.TestCase):
self._all_fine_test("unitest/test43.c")
def test044IfEqNull(self):
self._all_fine_test("unitest/test44.c")
self._generic_test("unitest/test44.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 5, 14), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 10, 14), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "var2", 7, 14) ] )
def test045IfNoEqNull(self):
self._all_fine_test("unitest/test45.c")
def test046IfElseNull(self):
self._all_fine_test("unitest/test46.c")
self._generic_test("unitest/test46.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "var2", 7, 14) ])
def test047Recycle(self):
lib = self._all_fine_test("unitest/test47.c")
self._check_var_state(lib, "var3", crust.crust.VALUE_NOT_NULL)
self._check_var_state(lib, "var3", crust.crust.VALUE_NOT_NULL, 0)
self._check_var_state(lib, "var3", crust.crust.VALUE_FREED, 1)
def test048Borrow(self):
lib = self._all_fine_test("unitest/test48.c")
......
......@@ -14,18 +14,14 @@ __crust_t__ unsigned char * calling3() {
return NULL;
}
void calling4(crust_t param) {
calling4(param); // a trick to free param and trigger only one error
}
void calling4(crust_t param);
void calling5(crust_t __crust_borrow__ param) {
int a = 5;
int b = a > 6 ? param->p1 : param->p2;
}
void calling6(int v) {
}
void calling6(int v);
void main() {
......@@ -49,7 +45,7 @@ void main() {
param1 = calling2();
param2 = calling3();
calling4(param1); // a trick to free param1 and trigger only one error
calling4(param2); // a trick to free param2 and trigger only one error
calling4(param4); // a trick to free param4 and trigger only one error
calling4(param1);
calling4(param2);
calling4(param4);
}
typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
void function() {
crust_t retval = function3(3,5); // ERROR: function3 doesn't exist
function3(3,5); // ERROR: function3 doesn't exist
}
void function(__crust_t__ int); // ERROR: the parameter is not a pointer
void function(__crust_t__ int); // ERROR: the CRUST parameter is not a pointer
void function(__crust_t__ int parameter); // ERROR: named parameter is not a pointer
void function(__crust_t__ int parameter); // ERROR: named CRUST parameter is not a pointer
typedef __crust_t__ unsigned char *crust_t;
void function(crust_t param1) {
void function() {
crust_t param4;
int retval = (param4 == NULL) ? 1 : 0; // ERROR: conditional depends on an uninitialized variable
__crust_disable__ // added here to ensure only one error per unitest
}
typedef __crust_t__ int * crust_t;
int function(crust_t param1) {
void function(crust_t param1) {
crust_t param4 = param1;
crust_t param5 = param1; // ERROR: assigning a previously freed variable (due to assign in line 4)
__crust_disable__ // added here to ensure only one error per unitest
// ERROR: param4 isn't freed
}
typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
void function() {
int v = 5;
crust_t param = (crust_t) v; // This is legal
__crust_disable__ // added here to ensure only one error per unitest
// ERROR: param is still in use at the end of the function
}
typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param1) {
void function() {
crust_t param = 5; // ERROR: assigning a constant (non-crust) to a crust variable
__crust_disable__ // added here to ensure only one error per unitest}
//ERROR: param is in use at the end of the function
}
typedef __crust_t__ unsigned char *crust_t;
crust_t function(crust_t param3) {
crust_t function();
function(NULL); // ERROR: the function returns a crust_t pointer, but it isn't stored
__crust_disable__ // added here to ensure only one error per unitest
void main() {
function(); // ERROR: the function returns a crust_t pointer, but it isn't stored
}
typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
int function(crust_t);
void main() {
crust_t param4;
function(param4); // ERROR: calling a function with an uninitialized parameter
__crust_disable__ // added here to ensure only one error per unitest
}
typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
int function(crust_t);
void main() {
int *param = 1;
function(param); // ERROR: calling a function passing a non-crust value as a crust parameter
__crust_disable__ // added here to ensure only one error per unitest
}
typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
void function(crust_t);
void main() {
function(2); // ERROR: calling a function passing a constant (non-crust) value as a crust parameter
__crust_disable__ // added here to ensure only one error per unitest
}
typedef __crust_t__ unsigned char *crust_t;
void main(crust_t param1) {
void main() {
crust_t a,b;
crust_t a, b;
a = b = 5; // ERROR: assigning a non-crust value to two crust variables
__crust_disable__ // added here to ensure only one error per unitest
// ERROR 'a' is considered initialized, but it is not used
}
......@@ -4,7 +4,9 @@ struct {
crust_t value;
} test;
int function(crust_t param3) {
void function2(crust_t);
void function() {
crust_t param4 = test.value; // this is legal
__crust_disable__ // added here to ensure only one error per unitest
function2(param4);
}
......@@ -4,7 +4,9 @@ struct {
crust_t value;
} test;
int function(crust_t param3) {
void function2(crust_t);
void function() {
crust_t param4 = test; // ERROR: assigning a non-crust variable into a crust variable
__crust_disable__ // added here to ensure only one error per unitest
function2(param4);
}
......@@ -2,7 +2,9 @@ typedef __crust_t__ unsigned char *crust_t;
crust_t test[5];
int function(crust_t param1) {
void function(crust_t);
void main() {
crust_t param4 = test[1]; // this is legal
__crust_disable__ // added here to ensure only one error per unitest
function(param4);
}
typedef __crust_t__ unsigned char *crust_t;
crust_t test[5];
int function() {
void function(crust_t);
void main() {
crust_t param4 = test; // ERROR: it is an array, not a crust_t element
__crust_disable__ // added here to ensure only one error per unitest
function(param4);
}
typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
int function(crust_t);
void main {
crust_t param4;
int retval = function(param4); // ERROR: param4 is used before being assigned
__crust_disable__ // added here to ensure only one error per unitest
//__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -4,7 +4,9 @@ struct {
crust_t value;
} *test;
int function(crust_t param3) {
void function(crust_t);
void main() {
crust_t param4 = test->value; // this is legal
__crust_disable__ // added here to ensure only one error per unitest
function(param4);
}
......@@ -9,5 +9,6 @@ void main(crust_t param) {
if (param == NULL) {
param = var2; // this is legal (assigning an object to a NULL variable)
}
__crust_disable__ // added here to ensure only one error per unitest
// ERROR: param isn't freed in none of the two points where it is initialized (line 5 and line 10).
// ERROR: var2 isn't freed (if param is not NULL, it won't be assigned var2)
}
......@@ -9,5 +9,5 @@ void main(crust_t param) {
main(param);
}
param = var2; // if param was NULL, var2 can be assigned; if it wasn't, "main(param)" was called, so now it is FREED and can be assigned
__crust_disable__ // added here to ensure only one error per unitest
main(param);
}
......@@ -11,5 +11,4 @@ void main(crust_t param) {
param = var2;
main(param); // all is legal
}
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -2,11 +2,15 @@ typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
crust_t main(crust_t __crust_recycle__ param) {
crust_t function(crust_t __crust_recycle__);
void function2(crust_t);
void main() {
crust_t var2 = (crust_t) 5;
crust_t var3;
var3 = main(var2); // This is legal
var3 = function(var2); // This is legal
__crust_debug__
function2(var3);
__crust_debug__
__crust_disable__ // added here to ensure only one error per unitest
}
typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
void function(crust_t param3) {
int retval = function(param3);
int retval2 = function(param3); // ERROR: param3 was freed at line 5, when is passed to "function"
return 0;
int retval2 = function(param3); // ERROR: param3 was freed at line 5, when passed to "function"
}
typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
void function(crust_t);
void main() {
int *param = 1;
int retval = function(param); // ERROR: passed non-crust variable as a crust parameter
__crust_disable__ // added here to ensure only one error per unitest
}
typedef __crust_t__ unsigned char *crust_t;
crust_t function(int param3) {
void function(int);
void main() {
crust_t param = NULL;
crust_t retval = function(param); // ERROR: passed a crust variable to a non-crust param
__crust_disable__ // added here to ensure only one error per unitest
function(param); // ERROR: passed a crust variable to a non-crust param
}
typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
void function(crust_t);
int retval = function(2); // ERROR: passed a constant (non-crust) as a crust parameter
__crust_disable__ // added here to ensure only one error per unitest
void main() {
function(2); // ERROR: passed a constant (non-crust) as a crust parameter
}
typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
void function(crust_t);
int retval = function(3,5); // ERROR: incorrect number of parameters
__crust_disable__ // added here to ensure only one error per unitest
void main() {
function(3,5); // ERROR: incorrect number of parameters
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment