Exemplo n.º 1
0
def run_quick_check(args,
                    context,
                    actions):
    '''
    This function implements the "quickcheck" feature.
    No result is stored to a database
    '''

    enabled_analyzers = set()

    enabled_analyzers = analyzer_types.check_supported_analyzers(args.analyzers,
                                                                 context)

    actions = prepare_actions(actions, enabled_analyzers)

    analyzer_config_map = {}

    analyzer_config_map = analyzer_types.build_config_handlers(args,
                                                               context,
                                                               enabled_analyzers)

    for action in actions:
        check_data = (args,
                      action,
                      context,
                      analyzer_config_map,
                      None,
                      args.workspace,
                      False)

        analysis_manager.check(check_data)
Exemplo n.º 2
0
def run_quick_check(args,
                    context,
                    actions):
    """
    This function implements the "quickcheck" feature.
    No result is stored to a database.
    """

    enabled_analyzers = analyzer_types. \
        check_supported_analyzers(args.analyzers, context)

    actions = prepare_actions(actions, enabled_analyzers)

    analyzer_config_map = \
        analyzer_types.build_config_handlers(args,
                                             context,
                                             enabled_analyzers)

    __print_analyzer_version(context, analyzer_config_map)

    LOG.info("Static analysis is starting ...")

    analysis_manager.start_workers(args,
                                   actions,
                                   context,
                                   analyzer_config_map,
                                   None,
                                   False)
Exemplo n.º 3
0
def handle_list_checkers(args):
    """
    List the supported checkers by the analyzers.
    List the default enabled and disabled checkers in the config.
    """
    context = generic_package_context.get_context()
    enabled_analyzers = args.analyzers
    analyzer_environment = analyzer_env.get_check_env(
        context.path_env_extra,
        context.ld_lib_path_extra)

    if not enabled_analyzers:
        # Noting set list checkers for all supported analyzers.
        enabled_analyzers = list(analyzer_types.supported_analyzers)

    enabled_analyzer_types = set()
    for ea in enabled_analyzers:
        if ea not in analyzer_types.supported_analyzers:
            LOG.info('Not supported analyzer ' + str(ea))
            sys.exit(1)
        else:
            enabled_analyzer_types.add(ea)

    analyzer_config_map = \
        analyzer_types.build_config_handlers(args,
                                             context,
                                             enabled_analyzer_types)

    for ea in enabled_analyzers:
        # Get the config.
        config_handler = analyzer_config_map.get(ea)
        source_analyzer = \
            analyzer_types.construct_analyzer_type(ea,
                                                   config_handler,
                                                   None)

        checkers = source_analyzer.get_analyzer_checkers(config_handler,
                                                         analyzer_environment)

        default_checker_cfg = context.default_checkers_config.get(
            ea + '_checkers')

        analyzer_types.initialize_checkers(config_handler,
                                           checkers,
                                           default_checker_cfg)
        for checker_name, value in config_handler.checks().items():
            enabled, description = value
            if enabled:
                print(' + {0:50} {1}'.format(checker_name, description))
            else:
                print(' - {0:50} {1}'.format(checker_name, description))
Exemplo n.º 4
0
def handle_list_checkers(args):
    """
    List the supported checkers by the analyzers.
    List the default enabled and disabled checkers in the config.
    """
    context = generic_package_context.get_context()
    enabled_analyzers = args.analyzers
    analyzer_environment = analyzer_env.get_check_env(context.path_env_extra,
                                                      context.ld_lib_path_extra)

    if not enabled_analyzers:
        # Noting set list checkers for all supported analyzers.
        enabled_analyzers = list(analyzer_types.supported_analyzers)

    enabled_analyzer_types = set()
    for ea in enabled_analyzers:
        if ea not in analyzer_types.supported_analyzers:
            LOG.info('Not supported analyzer ' + str(ea))
            sys.exit(1)
        else:
            enabled_analyzer_types.add(ea)

    analyzer_config_map = \
        analyzer_types.build_config_handlers(args,
                                             context,
                                             enabled_analyzer_types)

    for ea in enabled_analyzers:
        # Get the config.
        config_handler = analyzer_config_map.get(ea)
        source_analyzer = analyzer_types.construct_analyzer_type(ea,
                                                                 config_handler,
                                                                 None)

        checkers = source_analyzer.get_analyzer_checkers(config_handler,
                                                         analyzer_environment)

        default_checker_cfg = context.default_checkers_config.get(
            ea + '_checkers')

        analyzer_types.initialize_checkers(config_handler,
                                           checkers,
                                           default_checker_cfg)
        for checker_name, value in config_handler.checks().items():
            enabled, description = value
            if enabled:
                print(' + {0:50} {1}'.format(checker_name, description))
            else:
                print(' - {0:50} {1}'.format(checker_name, description))
Exemplo n.º 5
0
def run_quick_check(args, context, actions):
    """
    This function implements the "quickcheck" feature.
    No result is stored to a database.
    """

    enabled_analyzers = analyzer_types. \
        check_supported_analyzers(args.analyzers, context)

    actions = prepare_actions(actions, enabled_analyzers)

    analyzer_config_map = \
        analyzer_types.build_config_handlers(args,
                                             context,
                                             enabled_analyzers)

    __print_analyzer_version(context, analyzer_config_map)

    LOG.info("Static analysis is starting ...")

    analysis_manager.start_workers(args, actions, context, analyzer_config_map,
                                   _get_skip_handler(args), False)
def run_quick_check(args, context, actions):
    '''
    This function implements the "quickcheck" feature.
    No result is stored to a database
    '''

    enabled_analyzers = set()

    enabled_analyzers = analyzer_types.check_supported_analyzers(
        args.analyzers, context)

    actions = prepare_actions(actions, enabled_analyzers)

    analyzer_config_map = {}

    analyzer_config_map = analyzer_types.build_config_handlers(
        args, context, enabled_analyzers)

    for action in actions:
        check_data = (args, action, context, analyzer_config_map, None,
                      args.workspace, False)

        analysis_manager.check(check_data)
Exemplo n.º 7
0
def run_check(args, actions, context):
    """
    prepare:
    - analyzer config handlers
    - skiplist handling
    - analyzer severity levels

    stores analysis related data to the database and starts the analysis
    """

    if args.jobs <= 0:
        args.jobs = 1

    LOG.debug_analyzer("Checking supported analyzers.")
    enabled_analyzers = analyzer_types.check_supported_analyzers(
        args.analyzers,
        context)

    # load severity map from config file
    LOG.debug_analyzer("Loading checker severity map.")
    if os.path.exists(context.checkers_severity_map_file):
        with open(context.checkers_severity_map_file, 'r') as sev_conf_file:
            severity_config = sev_conf_file.read()

        context.severity_map = json.loads(severity_config)

    actions = prepare_actions(actions, enabled_analyzers)

    analyzer_config_map = {}

    package_version = context.version['major'] + '.' + context.version['minor']

    suppress_file = ''
    try:
        suppress_file = os.path.realpath(args.suppress)
    except AttributeError:
        LOG.debug_analyzer('Suppress file was not set in the command line')


    # Create one skip list handler shared between the analysis manager workers
    skip_handler = None
    try:
        if args.skipfile:
            LOG.debug_analyzer("Creating skiplist handler.")
            skip_handler = skiplist_handler.SkipListHandler(args.skipfile)
    except AttributeError:
        LOG.debug_analyzer('Skip file was not set in the command line')


    with client.get_connection() as connection:
        context.run_id = connection.add_checker_run(' '.join(sys.argv),
                                                    args.name,
                                                    package_version,
                                                    args.force)

        # clean previous suppress information
        client.clean_suppress(connection, context.run_id)

        if os.path.exists(suppress_file):
            client.send_suppress(context.run_id, connection, suppress_file)

        analyzer_config_map = analyzer_types.build_config_handlers(args,
                                                                   context,
                                                                   enabled_analyzers,
                                                                   connection)
        if skip_handler:
            connection.add_skip_paths(context.run_id,
                                      skip_handler.get_skiplist())

    LOG.info("Static analysis is starting ...")
    start_time = time.time()

    analysis_manager.start_workers(args,
                                   actions,
                                   context,
                                   analyzer_config_map,
                                   skip_handler)

    end_time = time.time()

    with client.get_connection() as connection:
        connection.finish_checker_run(context.run_id)

    LOG.info("Analysis length: " + str(end_time - start_time) + " sec.")
def run_check(args, actions, context):
    """
    prepare:
    - analyzer config handlers
    - skiplist handling
    - analyzer severity levels

    stores analysis related data to the database and starts the analysis
    """

    if args.jobs <= 0:
        args.jobs = 1

    LOG.debug_analyzer("Checking supported analyzers.")
    enabled_analyzers = analyzer_types.check_supported_analyzers(
        args.analyzers, context)

    # load severity map from config file
    LOG.debug_analyzer("Loading checker severity map.")
    if os.path.exists(context.checkers_severity_map_file):
        with open(context.checkers_severity_map_file, 'r') as sev_conf_file:
            severity_config = sev_conf_file.read()

        context.severity_map = json.loads(severity_config)

    actions = prepare_actions(actions, enabled_analyzers)

    analyzer_config_map = {}

    package_version = context.version['major'] + '.' + context.version['minor']

    suppress_file = ''
    try:
        suppress_file = os.path.realpath(args.suppress)
    except AttributeError:
        LOG.debug_analyzer('Suppress file was not set in the command line')

    # Create one skip list handler shared between the analysis manager workers
    skip_handler = None
    try:
        if args.skipfile:
            LOG.debug_analyzer("Creating skiplist handler.")
            skip_handler = skiplist_handler.SkipListHandler(args.skipfile)
    except AttributeError:
        LOG.debug_analyzer('Skip file was not set in the command line')

    with client.get_connection() as connection:
        context.run_id = connection.add_checker_run(' '.join(sys.argv),
                                                    args.name, package_version,
                                                    args.force)

        # clean previous suppress information
        client.clean_suppress(connection, context.run_id)

        if os.path.exists(suppress_file):
            client.send_suppress(context.run_id, connection, suppress_file)

        analyzer_config_map = analyzer_types.build_config_handlers(
            args, context, enabled_analyzers, connection)
        if skip_handler:
            connection.add_skip_paths(context.run_id,
                                      skip_handler.get_skiplist())

    LOG.info("Static analysis is starting ...")
    start_time = time.time()

    analysis_manager.start_workers(args, actions, context, analyzer_config_map,
                                   skip_handler)

    end_time = time.time()

    with client.get_connection() as connection:
        connection.finish_checker_run(context.run_id)

    LOG.info("Analysis length: " + str(end_time - start_time) + " sec.")