diff options
Diffstat (limited to 'src/analysis')
| -rw-r--r-- | src/analysis/scan/exprs/access.c | 2 | ||||
| -rw-r--r-- | src/analysis/scan/exprs/call.c | 4 | ||||
| -rw-r--r-- | src/analysis/scan/exprs/handler.c | 3 | ||||
| -rw-r--r-- | src/analysis/scan/exprs/literal.c | 21 | ||||
| -rw-r--r-- | src/analysis/scan/grammar.y | 129 | ||||
| -rw-r--r-- | src/analysis/scan/patterns/backends/acism.c | 15 | ||||
| -rw-r--r-- | src/analysis/scan/patterns/token.c | 2 | ||||
| -rw-r--r-- | src/analysis/scan/rule.c | 3 | ||||
| -rw-r--r-- | src/analysis/scan/space.c | 2 | 
9 files changed, 164 insertions, 17 deletions
diff --git a/src/analysis/scan/exprs/access.c b/src/analysis/scan/exprs/access.c index a1331b0..342c2d7 100644 --- a/src/analysis/scan/exprs/access.c +++ b/src/analysis/scan/exprs/access.c @@ -391,6 +391,8 @@ GScanRegisteredItem *_g_scan_named_access_prepare_reduction(const GScanNamedAcce          g_scan_registered_item_resolve(base, expr->target, ctx, scope, &result); +        g_object_unref(G_OBJECT(base)); +      }      /** diff --git a/src/analysis/scan/exprs/call.c b/src/analysis/scan/exprs/call.c index e335933..3997ff6 100644 --- a/src/analysis/scan/exprs/call.c +++ b/src/analysis/scan/exprs/call.c @@ -326,6 +326,10 @@ static ScanReductionState g_scan_pending_call_reduce(const GScanPendingCall *exp              {                  if (new_args != NULL)                      new_args[i] = new; + +                else +                    g_object_unref(G_OBJECT(new)); +              }          } diff --git a/src/analysis/scan/exprs/handler.c b/src/analysis/scan/exprs/handler.c index 8aab9e5..ea24443 100644 --- a/src/analysis/scan/exprs/handler.c +++ b/src/analysis/scan/exprs/handler.c @@ -168,6 +168,9 @@ static void g_scan_pattern_handler_dispose(GScanPatternHandler *handler)  static void g_scan_pattern_handler_finalize(GScanPatternHandler *handler)  { +    if (handler->patterns != NULL) +        free(handler->patterns); +      G_OBJECT_CLASS(g_scan_pattern_handler_parent_class)->finalize(G_OBJECT(handler));  } diff --git a/src/analysis/scan/exprs/literal.c b/src/analysis/scan/exprs/literal.c index b1a094c..b7aed5b 100644 --- a/src/analysis/scan/exprs/literal.c +++ b/src/analysis/scan/exprs/literal.c @@ -124,6 +124,8 @@ static void g_scan_literal_expression_init(GScanLiteralExpression *expr)  {      G_SCAN_EXPRESSION(expr)->state = SRS_REDUCED; +    memset(&expr->value, 0, sizeof(expr->value)); +  } @@ -160,6 +162,25 @@ static void g_scan_literal_expression_dispose(GScanLiteralExpression *expr)  static void g_scan_literal_expression_finalize(GScanLiteralExpression *expr)  { +    switch (expr->value_type) +    { +        case LVT_STRING: +            exit_szstr(&expr->value.string); +            break; + +        case LVT_REG_EXPR: +            if (expr->value.regex != NULL) +            { +                free(expr->value.regex); +                regfree(&expr->value.preg); +            } +            break; + +        default: +            break; + +    } +      G_OBJECT_CLASS(g_scan_literal_expression_parent_class)->finalize(G_OBJECT(expr));  } diff --git a/src/analysis/scan/grammar.y b/src/analysis/scan/grammar.y index f31a5d1..ecaeb1f 100644 --- a/src/analysis/scan/grammar.y +++ b/src/analysis/scan/grammar.y @@ -331,7 +331,11 @@ YY_DECL;               rules : /* empty */                     | external rules -                   | rule rules { g_content_scanner_add_rule(scanner, $1); } +                   | rule rules +                   { +                       g_content_scanner_add_rule(scanner, $1); +                       g_object_unref(G_OBJECT($1)); +                   }                     ; @@ -538,9 +542,11 @@ YY_DECL;                         {                             $$ = g_scan_modifier_pipe_new();                             g_scan_modifier_pipe_add(G_SCAN_MODIFIER_PIPE($$), $1); +                           g_object_unref(G_OBJECT($1));                         }                         g_scan_modifier_pipe_add(G_SCAN_MODIFIER_PIPE($$), $3); +                       g_object_unref(G_OBJECT($3));                     }                     ; @@ -575,6 +581,7 @@ YY_DECL;                         {                             $$ = g_scan_modifier_list_new();                             g_scan_modifier_list_add(G_SCAN_MODIFIER_LIST($$), $1); +                           g_object_unref(G_OBJECT($1));                         }                         status = g_scan_modifier_list_add(G_SCAN_MODIFIER_LIST($$), $2); @@ -582,9 +589,10 @@ YY_DECL;                         {                             if (1)                                 log_simple_message(LMT_WARNING, "modifier already taken into account!"); -                           g_object_unref(G_OBJECT($2));                         } +                       g_object_unref(G_OBJECT($2)); +                     }                     ; @@ -634,6 +642,9 @@ YY_DECL;                         }                         _status = g_scan_token_customizer_attach_modifier(G_SCAN_TOKEN_CUSTOMIZER($$), _mod); + +                       g_object_unref(G_OBJECT(_mod)); +                         if (!_status)                         {                             char *_msg; @@ -1065,6 +1076,7 @@ YY_DECL;                  | chain_items "." chain_item                  {                      g_scan_named_access_attach_next(G_SCAN_NAMED_ACCESS($1), G_SCAN_NAMED_ACCESS($3)); +                    g_object_unref(G_OBJECT($3));                      $$ = $1;                  }                  ; @@ -1107,58 +1119,143 @@ YY_DECL;                  }                  ; -   logical_expr : cexpression "and" cexpression { $$ = g_scan_logical_operation_new(BOT_AND, $1, $3); } -                | cexpression "or" cexpression  { $$ = g_scan_logical_operation_new(BOT_OR, $1, $3); } -                | "not" "(" cexpression ")"     { $$ = g_scan_logical_operation_new(BOT_NOT, $3, NULL); } +   logical_expr : cexpression "and" cexpression +                { +                    $$ = g_scan_logical_operation_new(BOT_AND, $1, $3); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3)); +                } +                | cexpression "or" cexpression +                { +                    $$ = g_scan_logical_operation_new(BOT_OR, $1, $3); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3)); +                } +                | "not" "(" cexpression ")" +                { +                    $$ = g_scan_logical_operation_new(BOT_NOT, $3, NULL); +                    g_object_unref(G_OBJECT($3)); +                }                  ; -relational_expr : cexpression "<" cexpression  { $$ = g_scan_relational_operation_new(RCO_LT, $1, $3); } -                | cexpression "<=" cexpression { $$ = g_scan_relational_operation_new(RCO_LE, $1, $3); } -                | cexpression "==" cexpression { $$ = g_scan_relational_operation_new(RCO_EQ, $1, $3); } -                | cexpression "!=" cexpression { $$ = g_scan_relational_operation_new(RCO_NE, $1, $3); } -                | cexpression ">" cexpression  { $$ = g_scan_relational_operation_new(RCO_GT, $1, $3); } -                | cexpression ">=" cexpression { $$ = g_scan_relational_operation_new(RCO_GE, $1, $3); } +relational_expr : cexpression "<" cexpression +                { +                    $$ = g_scan_relational_operation_new(RCO_LT, $1, $3); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3)); +                } +                | cexpression "<=" cexpression +                { +                    $$ = g_scan_relational_operation_new(RCO_LE, $1, $3); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3)); +                } +                | cexpression "==" cexpression +                { +                    $$ = g_scan_relational_operation_new(RCO_EQ, $1, $3); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3)); +                } +                | cexpression "!=" cexpression +                { +                    $$ = g_scan_relational_operation_new(RCO_NE, $1, $3); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3)); +                } +                | cexpression ">" cexpression +                { +                    $$ = g_scan_relational_operation_new(RCO_GT, $1, $3); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3)); +                } +                | cexpression ">=" cexpression +                { +                    $$ = g_scan_relational_operation_new(RCO_GE, $1, $3); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3)); +                }                  ;        string_op : cexpression "contains" cexpression                  {                      $$ = g_scan_string_operation_new(SOT_CONTAINS, $1, $3, true); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3));                  }                  | cexpression "startswith" cexpression                  {                      $$ = g_scan_string_operation_new(SOT_STARTSWITH, $1, $3, true); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3));                  }                  | cexpression "endswith" cexpression                  {                      $$ = g_scan_string_operation_new(SOT_ENDSWITH, $1, $3, true); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3));                  }                  | cexpression "matches" cexpression                  {                      $$ = g_scan_string_operation_new(SOT_MATCHES, $1, $3, true); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3));                  }                  | cexpression "icontains" cexpression                  {                      $$ = g_scan_string_operation_new(SOT_CONTAINS, $1, $3, false); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3));                  }                  | cexpression "istartswith" cexpression                  {                      $$ = g_scan_string_operation_new(SOT_STARTSWITH, $1, $3, false); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3));                  }                  | cexpression "iendswith" cexpression                  {                      $$ = g_scan_string_operation_new(SOT_ENDSWITH, $1, $3, false); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3));                  }                  | cexpression "iequals" cexpression                  {                      $$ = g_scan_string_operation_new(SOT_IEQUALS, $1, $3, false); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3));                  }                  ; -    arithm_expr : cexpression "+" cexpression { $$ = g_scan_arithmetic_operation_new(AEO_PLUS, $1, $3); } -                | cexpression "-" cexpression { $$ = g_scan_arithmetic_operation_new(AEO_MINUS, $1, $3); } -                | cexpression "*" cexpression { $$ = g_scan_arithmetic_operation_new(AEO_MUL, $1, $3); } -                | cexpression "/" cexpression { $$ = g_scan_arithmetic_operation_new(AEO_DIV, $1, $3); } -                | cexpression "%" cexpression { $$ = g_scan_arithmetic_operation_new(AEO_MOD, $1, $3); } +    arithm_expr : cexpression "+" cexpression +                { +                    $$ = g_scan_arithmetic_operation_new(AEO_PLUS, $1, $3); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3)); +                } +                | cexpression "-" cexpression +                { +                    $$ = g_scan_arithmetic_operation_new(AEO_MINUS, $1, $3); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3)); +                } +                | cexpression "*" cexpression +                { +                    $$ = g_scan_arithmetic_operation_new(AEO_MUL, $1, $3); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3)); +                } +                | cexpression "/" cexpression +                { +                    $$ = g_scan_arithmetic_operation_new(AEO_DIV, $1, $3); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3)); +                } +                | cexpression "%" cexpression +                { +                    $$ = g_scan_arithmetic_operation_new(AEO_MOD, $1, $3); +                    g_object_unref(G_OBJECT($1)); +                    g_object_unref(G_OBJECT($3)); +                }                  ; diff --git a/src/analysis/scan/patterns/backends/acism.c b/src/analysis/scan/patterns/backends/acism.c index 97f8561..70e9a42 100644 --- a/src/analysis/scan/patterns/backends/acism.c +++ b/src/analysis/scan/patterns/backends/acism.c @@ -217,6 +217,21 @@ static void g_acism_backend_dispose(GAcismBackend *backend)  static void g_acism_backend_finalize(GAcismBackend *backend)  { +    if (backend->sources != NULL) +        free(backend->sources); + +    if (backend->nodes != NULL) +        free(backend->nodes); + +    if (backend->bitmap_usage != NULL) +        delete_bit_field(backend->bitmap_usage); + +    if (backend->states != NULL) +        free(backend->states); + +    if (backend->pids != NULL) +        free(backend->pids); +      G_OBJECT_CLASS(g_acism_backend_parent_class)->finalize(G_OBJECT(backend));  } diff --git a/src/analysis/scan/patterns/token.c b/src/analysis/scan/patterns/token.c index 030e4a1..e5eb287 100644 --- a/src/analysis/scan/patterns/token.c +++ b/src/analysis/scan/patterns/token.c @@ -141,6 +141,8 @@ static void g_bytes_token_init(GBytesToken *token)  static void g_bytes_token_dispose(GBytesToken *token)  { +    g_clear_object(&token->root); +      G_OBJECT_CLASS(g_bytes_token_parent_class)->dispose(G_OBJECT(token));  } diff --git a/src/analysis/scan/rule.c b/src/analysis/scan/rule.c index d4420b7..e3f84d4 100644 --- a/src/analysis/scan/rule.c +++ b/src/analysis/scan/rule.c @@ -165,6 +165,9 @@ static void g_scan_rule_finalize(GScanRule *rule)      if (rule->tags != NULL)          free(rule->tags); +    if (rule->bytes_locals != NULL) +        free(rule->bytes_locals); +      G_OBJECT_CLASS(g_scan_rule_parent_class)->finalize(G_OBJECT(rule));  } diff --git a/src/analysis/scan/space.c b/src/analysis/scan/space.c index 7dd9082..1aaf8b8 100644 --- a/src/analysis/scan/space.c +++ b/src/analysis/scan/space.c @@ -274,7 +274,7 @@ bool g_scan_namespace_register_item(GScanNamespace *space, GScanRegisteredItem *          g_object_ref(G_OBJECT(child));          space->names = realloc(space->names, space->count * sizeof(char *)); -        space->names[space->count - 1] = strdup(name); +        space->names[space->count - 1] = name;      }  | 
