From 9c4d426f7b83903f80a482b684a9945feddbf4df Mon Sep 17 00:00:00 2001 From: FanWuUCL Date: Wed, 4 Nov 2015 17:40:28 +0000 Subject: [PATCH] fix bugs and modify CRCR options --- Makefile | 2 +- src/include/ASTNodeUtil.h | 22 ++++++++++++++-- src/mutation/ASTNodeUtil.c | 26 +++++++++++++++++++ .../REDAWZ/replace_calloc_size_with_zero.c | 17 +++++++++--- .../REDAWZ/replace_malloc_size_with_zero.c | 17 +++++++++--- .../REM2A/replace_malloc_with_alloca.c | 26 ++++++++++++++----- .../CRCR/integer_constant_replacement.c | 23 +++++++--------- src/operators/REC2A.c | 1 + src/operators/REC2M.c | 1 + src/operators/REDAWN.c | 2 ++ 10 files changed, 108 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index b7a1210..205f0d0 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ SOURCES=src/*.c OBJECTS= App.o ASTNode.o ASTNodeUtil.o ASTPrinter.o ASTUnit.o Milu3.o MultiProcessing.o Mutant.o MutantExecutor.o MutantSet.o MutationId.o MutationOperator.o MutationTemplate.o Mutator.o Options.o Project.o TestInput.o Utility.o $(OPOBJ) $(MUTOBJ) -MUTOBJ=add_arithmetic_assignment_replacement.o add_arithmetic_replacement.o and_logical_negation.o and_logical_replacement.o austin_add_arithmetic_replacement.o austin_and_logical_negation.o austin_and_logical_replacement.o austin_divide_arithmetic_replacement.o austin_equal_relational_replacement.o austin_greater_equal_relational_replacement.o austin_greater_relationa_replacement.o austin_integer_constant_replacement.o austin_less_equal_relational_replacement.o austin_less_relational_replacement.o austin_modulus_arithmetic_replacement.o austin_multiply_arithmetic_replacement.o austin_not_equal_relational_replacement.o austin_or_logical_negation.o austin_or_logical_replacement.o austin_subtract_arithmetic_replacement.o bitwise_and_logical_assignment_replacement.o bitwise_and_logical_replacement.o bitwise_or_logical_assignment_replacement.o bitwise_or_logical_replacement.o divide_arithmetic_assignment_replacement.o divide_arithmetic_replacement.o equal_relational_replacement.o greater_equal_relational_replacement.o greater_relational_replacement.o if_expression_negation_replacement.o integer_constant_replacement.o less_equal_relational_replacement.o less_relational_replacement.o modulus_arithmetic_assignment_replacement.o modulus_arithmetic_replacement.o multiply_arithmetic_assignment_replacement.o multiply_arithmetic_replacement.o not_equal_relational_replacement.o or_logical_negation.o or_logical_replacement.o postfix_decrement_replacement.o postfix_increment_replacement.o prefix_decrement_replacement.o prefix_increment_replacement.o subtract_arithmetic_assignment_replacement.o subtract_arithmetic_replacement.o break_continue_replacement.o float_constant_replacement.o statement_deletion.o integer_var_abs_insertion.o float_var_abs_insertion.o integer_var_uoi_insertion.o while_expression_negation_replacement.o remove_null_assignment.o replace_calloc_with_null.o replace_malloc_with_null.o replace_malloc_size_with_zero.o replace_calloc_size_with_zero.o replace_sizeof_argument_with_pointer_equivalent.o replace_sizeof_argument_with_nonpointer_equivalent.o replace_calloc_with_malloc.o remove_free_statement.o replace_malloc_with_alloca.o replace_calloc_with_alloca.o +MUTOBJ=add_arithmetic_assignment_replacement.o add_arithmetic_replacement.o and_logical_negation.o and_logical_replacement.o austin_add_arithmetic_replacement.o austin_and_logical_negation.o austin_and_logical_replacement.o austin_divide_arithmetic_replacement.o austin_equal_relational_replacement.o austin_greater_equal_relational_replacement.o austin_greater_relationa_replacement.o austin_integer_constant_replacement.o austin_less_equal_relational_replacement.o austin_less_relational_replacement.o austin_modulus_arithmetic_replacement.o austin_multiply_arithmetic_replacement.o austin_not_equal_relational_replacement.o austin_or_logical_negation.o austin_or_logical_replacement.o austin_subtract_arithmetic_replacement.o bitwise_and_logical_assignment_replacement.o bitwise_and_logical_replacement.o bitwise_or_logical_assignment_replacement.o bitwise_or_logical_replacement.o divide_arithmetic_assignment_replacement.o divide_arithmetic_replacement.o equal_relational_replacement.o greater_equal_relational_replacement.o greater_relational_replacement.o if_expression_negation_replacement.o integer_constant_replacement.o less_equal_relational_replacement.o less_relational_replacement.o modulus_arithmetic_assignment_replacement.o modulus_arithmetic_replacement.o multiply_arithmetic_assignment_replacement.o multiply_arithmetic_replacement.o not_equal_relational_replacement.o or_logical_negation.o or_logical_replacement.o postfix_decrement_replacement.o postfix_increment_replacement.o prefix_decrement_replacement.o prefix_increment_replacement.o subtract_arithmetic_assignment_replacement.o subtract_arithmetic_replacement.o break_continue_replacement.o float_constant_replacement.o statement_deletion.o integer_var_abs_insertion.o float_var_abs_insertion.o integer_var_uoi_insertion.o while_expression_negation_replacement.o remove_null_assignment.o replace_calloc_with_null.o replace_malloc_with_null.o replace_malloc_size_with_zero.o replace_calloc_size_with_zero.o replace_sizeof_argument_with_pointer_equivalent.o replace_sizeof_argument_with_nonpointer_equivalent.o replace_calloc_with_malloc.o remove_free_statement.o replace_malloc_with_alloca.o replace_calloc_with_alloca.o replace_cast_calloc_with_alloca.o replace_cast_calloc_with_malloc.o replace_cast_calloc_with_null.o replace_cast_malloc_with_null.o OPOBJ=Austin_CRCR.o Austin_OAAN.o Austin_OLLN.o Austin_OLNG.o Austin_ORRN.o CRCR.o ABS.o OAAA.o OAAN.o OBBA.o OBBN.o OCNG.o OIDO.o OLLN.o OLNG.o ORRN.o SBRC.o SSDL.o UOI.o RMNA.o REDAWN.o REDAWZ.o RESOTPE.o REMSOTP.o REC2M.o RMFS.o REM2A.o REC2A.o diff --git a/src/include/ASTNodeUtil.h b/src/include/ASTNodeUtil.h index 58933d0..45b263f 100644 --- a/src/include/ASTNodeUtil.h +++ b/src/include/ASTNodeUtil.h @@ -560,14 +560,32 @@ gboolean is_ASTNode_null_assignment(const ASTNode * node); gboolean is_ASTNode_calloc_call(const ASTNode * node); /** - * \brief Check if the given node is the root of a calloc call + * \brief Check if the given node is the root of a malloc call * * \node The given node to check. * - * \return TRUE if the given node is the root of a calloc call. + * \return TRUE if the given node is the root of a malloc call. **/ gboolean is_ASTNode_malloc_call(const ASTNode * node); +/** + * \brief Check if the given node is the root of a calloc call with a cast in front + * + * \node The given node to check. + * + * \return TRUE if the given node is the root of a calloc call with a cast in front. + **/ +gboolean is_ASTNode_cast_calloc_call(const ASTNode * node); + +/** + * \brief Check if the given node is the root of a malloc call with a cast in front + * + * \node The given node to check. + * + * \return TRUE if the given node is the root of a malloc call with a cast in front. + **/ +gboolean is_ASTNode_cast_malloc_call(const ASTNode * node); + /** * \brief Check if the given node has calloc call in it's children nodes * diff --git a/src/mutation/ASTNodeUtil.c b/src/mutation/ASTNodeUtil.c index 19eec45..c1d2a13 100644 --- a/src/mutation/ASTNodeUtil.c +++ b/src/mutation/ASTNodeUtil.c @@ -474,6 +474,32 @@ gboolean is_ASTNode_malloc_call(const ASTNode * node) return FALSE; } +gboolean is_ASTNode_cast_calloc_call(const ASTNode * node) +{ + ASTNode * child; + if(is_ASTNode_has_kind(node, NodeKind_CStyleCastExpr)){ + if(!node->children || !node->children->next_sibling) return FALSE; + child=node->children->next_sibling; + if(is_ASTNode_has_kind(child, NodeKind_CallExpr) && is_ASTNode_has_text(child, "calloc")){ + return TRUE; + } + } + return FALSE; +} + +gboolean is_ASTNode_cast_malloc_call(const ASTNode * node) +{ + ASTNode * child; + if(is_ASTNode_has_kind(node, NodeKind_CStyleCastExpr)){ + if(!node->children || !node->children->next_sibling) return FALSE; + child=node->children->next_sibling; + if(is_ASTNode_has_kind(child, NodeKind_CallExpr) && is_ASTNode_has_text(child, "malloc")){ + return TRUE; + } + } + return FALSE; +} + gboolean has_ASTNode_calloc_call(const ASTNode * node) { ASTNode * child; diff --git a/src/mutators/memory_c/REDAWZ/replace_calloc_size_with_zero.c b/src/mutators/memory_c/REDAWZ/replace_calloc_size_with_zero.c index 962cee3..2a3d2b9 100644 --- a/src/mutators/memory_c/REDAWZ/replace_calloc_size_with_zero.c +++ b/src/mutators/memory_c/REDAWZ/replace_calloc_size_with_zero.c @@ -49,13 +49,19 @@ Mutator * mutator_milu_replace_calloc_size_with_zero() static gboolean mutator_milu_replace_calloc_size_with_zero_node_checking(ASTNode * node) { - return is_ASTNode_calloc_call(node); + return is_ASTNode_calloc_call(node) || is_ASTNode_cast_calloc_call(node); } static gboolean mutator_milu_replace_calloc_size_with_zero_mutate(ASTNode * node, gint type) { ASTNode * replace; - ASTNode * child=node->children->children->next_sibling; + ASTNode * child; + if(is_ASTNode_cast_calloc_call(node)){ + child=node->children->next_sibling->children->next_sibling; + } + else{ + child=node->children->children->next_sibling; + } switch(type) { case 1: @@ -74,7 +80,12 @@ static gboolean mutator_milu_replace_calloc_size_with_zero_mutate(ASTNode * node static gboolean mutator_milu_replace_calloc_size_with_zero_clean(ASTNode * node, gint type) { - node=node->children->children->next_sibling; + if(is_ASTNode_cast_calloc_call(node)){ + node=node->children->next_sibling->children->next_sibling; + } + else{ + node=node->children->children->next_sibling; + } replace_subtree_with(node, tmpNode); tmpNode=NULL; return TRUE; diff --git a/src/mutators/memory_c/REDAWZ/replace_malloc_size_with_zero.c b/src/mutators/memory_c/REDAWZ/replace_malloc_size_with_zero.c index 19d633d..5245118 100644 --- a/src/mutators/memory_c/REDAWZ/replace_malloc_size_with_zero.c +++ b/src/mutators/memory_c/REDAWZ/replace_malloc_size_with_zero.c @@ -49,13 +49,19 @@ Mutator * mutator_milu_replace_malloc_size_with_zero() static gboolean mutator_milu_replace_malloc_size_with_zero_node_checking(ASTNode * node) { - return is_ASTNode_malloc_call(node); + return is_ASTNode_malloc_call(node) || is_ASTNode_cast_malloc_call(node); } static gboolean mutator_milu_replace_malloc_size_with_zero_mutate(ASTNode * node, gint type) { ASTNode * replace; - ASTNode * child=node->children->children->next_sibling; + ASTNode * child; + if(is_ASTNode_cast_malloc_call(node)){ + child=node->children->next_sibling->children->next_sibling; + } + else{ + child=node->children->children->next_sibling; + } switch(type) { case 1: @@ -74,7 +80,12 @@ static gboolean mutator_milu_replace_malloc_size_with_zero_mutate(ASTNode * node static gboolean mutator_milu_replace_malloc_size_with_zero_clean(ASTNode * node, gint type) { - node=node->children->children->next_sibling; + if(is_ASTNode_cast_malloc_call(node)){ + node=node->children->next_sibling->children->next_sibling; + } + else{ + node=node->children->children->next_sibling; + } replace_subtree_with(node, tmpNode); tmpNode=NULL; return TRUE; diff --git a/src/mutators/memory_c/REM2A/replace_malloc_with_alloca.c b/src/mutators/memory_c/REM2A/replace_malloc_with_alloca.c index 1c128c1..2f59dd8 100644 --- a/src/mutators/memory_c/REM2A/replace_malloc_with_alloca.c +++ b/src/mutators/memory_c/REM2A/replace_malloc_with_alloca.c @@ -48,7 +48,7 @@ Mutator * mutator_milu_replace_malloc_with_alloca() static gboolean mutator_milu_replace_malloc_with_alloca_node_checking(ASTNode * node) { - return is_ASTNode_malloc_call(node); + return is_ASTNode_malloc_call(node) || is_ASTNode_cast_malloc_call(node); } static gboolean mutator_milu_replace_malloc_with_alloca_mutate(ASTNode * node, gint type) @@ -56,9 +56,15 @@ static gboolean mutator_milu_replace_malloc_with_alloca_mutate(ASTNode * node, g switch(type) { case 1: - ASTNode_set_text(node, "alloca"); - ASTNode_set_text(node->children, "alloca"); - ASTNode_set_text(node->children->children, "alloca"); + if(is_ASTNode_malloc_call(node)){ + ASTNode_set_text(node, "alloca"); + ASTNode_set_text(node->children, "alloca"); + ASTNode_set_text(node->children->children, "alloca"); + } + else{ + ASTNode_set_text(node->children->next_sibling, "alloca"); + ASTNode_set_text(node->children->next_sibling->children, "alloca"); + } return TRUE; default: @@ -70,8 +76,14 @@ static gboolean mutator_milu_replace_malloc_with_alloca_mutate(ASTNode * node, g static gboolean mutator_milu_replace_malloc_with_alloca_clean(ASTNode * node, gint type) { - ASTNode_set_text(node, "malloc"); - ASTNode_set_text(node->children, "malloc"); - ASTNode_set_text(node->children->children, "malloc"); + if(is_ASTNode_malloc_call(node)){ + ASTNode_set_text(node, "malloc"); + ASTNode_set_text(node->children, "malloc"); + ASTNode_set_text(node->children->children, "malloc"); + } + else{ + ASTNode_set_text(node->children->next_sibling, "malloc"); + ASTNode_set_text(node->children->next_sibling->children, "malloc"); + } return TRUE; } diff --git a/src/mutators/selective_c/CRCR/integer_constant_replacement.c b/src/mutators/selective_c/CRCR/integer_constant_replacement.c index 026be25..cbf7725 100644 --- a/src/mutators/selective_c/CRCR/integer_constant_replacement.c +++ b/src/mutators/selective_c/CRCR/integer_constant_replacement.c @@ -87,28 +87,25 @@ static gboolean mutator_milu_integer_constant_replacement_mutate(ASTNode * node, // set_ASTNode_text (node, g_strdup_printf("%d", atoi(node->text) * -1)); // return TRUE; case 6: - if(atoi(node->text) != 15) - set_ASTNode_text (node, "15"); + if(atoi(node->text) != 1023) + set_ASTNode_text (node, "1023"); else - set_ASTNode_text (node, "16"); + set_ASTNode_text (node, "511"); return TRUE; case 7: - if(atoi(node->text) != 255) - set_ASTNode_text (node, "255"); + if(atoi(node->text) != 32767) + set_ASTNode_text (node, "32767"); else - set_ASTNode_text (node, "256"); + set_ASTNode_text (node, "16383"); return TRUE; case 8: - if(atoi(node->text) != 1023) - set_ASTNode_text (node, "1023"); - else - set_ASTNode_text (node, "1024"); + set_ASTNode_text (node, g_strdup_printf("%d", atoi(node->text) * 2)); return TRUE; case 9: - if(atoi(node->text) != 32767) - set_ASTNode_text (node, "32767"); + if(atoi(node->text) >= 4 || atoi(node->text) <= -4) + set_ASTNode_text (node, g_strdup_printf("%d", atoi(node->text) / 2)); else - set_ASTNode_text (node, "32768"); + set_ASTNode_text (node, g_strdup_printf("%d", atoi(node->text) * 3)); return TRUE; default: break; diff --git a/src/operators/REC2A.c b/src/operators/REC2A.c index 0c7fa29..8052c44 100644 --- a/src/operators/REC2A.c +++ b/src/operators/REC2A.c @@ -38,6 +38,7 @@ Operator * get_REC2A_operator() Operator * op = mutation_operator_new(name, info); g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_calloc_with_alloca()); + g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_cast_calloc_with_alloca()); return op; } diff --git a/src/operators/REC2M.c b/src/operators/REC2M.c index 7c3eba4..a5f90e0 100644 --- a/src/operators/REC2M.c +++ b/src/operators/REC2M.c @@ -38,6 +38,7 @@ Operator * get_REC2M_operator() Operator * op = mutation_operator_new(name, info); g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_calloc_with_malloc()); + g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_cast_calloc_with_malloc()); return op; } diff --git a/src/operators/REDAWN.c b/src/operators/REDAWN.c index 5e90b74..0dec3e1 100644 --- a/src/operators/REDAWN.c +++ b/src/operators/REDAWN.c @@ -39,6 +39,8 @@ Operator * get_REDAWN_operator() g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_calloc_with_null()); g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_malloc_with_null()); + g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_cast_calloc_with_null()); + g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_cast_malloc_with_null()); return op; }