def pofilter(p):
        return True

    if args.predicates:

        def pofilter(p):
            return p.get_predicate_tag() in args.predicates

    openppos = capp.get_open_ppos()
    violations = capp.get_violations()
    delegated = capp.get_delegated()

    if len(openppos) > 0:
        print("Open proof obligations:\n" + ("=" * 80))
        print(RP.tag_file_function_pos_tostring(openppos, pofilter=pofilter))
    else:
        print("No open proof obligations found")

    if len(delegated) > 0:
        if args.xdelegated:
            print("Number of delegated ppo's: " + (str(len(delegated))))
        else:
            print("\n\nDelegated proof obligations:\n" + ("=" * 80))
            print(
                RP.tag_file_function_pos_tostring(delegated,
                                                  pofilter=pofilter))
    else:
        print("No delegated proof obligations found")

    if len(violations) > 0:
if __name__ == "__main__":

    args = parse()
    try:
        cpath = UF.get_juliet_testpath(args.cwe, args.test)
        UF.check_analysis_results(cpath)
    except UF.CHError as e:
        print(str(e.wrap()))
        exit(1)

    sempath = os.path.join(cpath, "semantics")

    try:
        cfapp = CApplication(sempath, args.cfile)
        cfile = cfapp.get_cfile()
    except UF.CHCFileNotFoundError as e:
        print(str(e.wrap()))
        exit(1)

    dc = ["deadcode"]

    if args.showcode:
        if args.open:
            print(
                RP.file_code_open_tostring(cfile,
                                           showinvs=args.showinvariants))
        else:
            print(RP.file_code_tostring(cfile, showinvs=args.showinvariants))

    print(RP.file_proofobligation_stats_tostring(cfile, extradsmethods=dc))
        lines.append("*" * 80)
        lines.append(("Function " + args.cfunction + " not found in file " +
                      cfile.name + "; function names available:"))
        lines.append("-" * 80)
        for n in cfile.functionnames:
            lines.append("  " + n)
        lines.append("*" * 80)
        print("\n".join(lines))
        exit(0)

    cfunction = cfile.get_function_by_name(args.cfunction)

    try:

        if args.open:
            print(RP.function_code_open_tostring(cfunction))
        elif args.predicate:
            print(
                RP.function_code_predicate_tostring(cfunction,
                                                    args.predicate,
                                                    showinvs=args.showinvs))
        else:
            print(RP.function_code_tostring(cfunction, showinvs=args.showinvs))

        print(RP.function_proofobligation_stats_tostring(cfunction))

    except IndexedTableError as e:
        print("\n" + ("*" * 80) + "\nThe analysis results format has changed" +
              "\nYou may have to re-run the analysis first: " + "\n" + e.msg +
              "\n" + ("*" * 80))
Ejemplo n.º 4
0
    sempath = os.path.join(args.path, 'semantics')

    cfapp = CApplication(sempath, args.cfile)
    cfile = cfapp.get_cfile()

    try:
        cfunction = cfile.get_function_by_name(args.cfunction)
    except UF.CHError as e:
        print(str(e.wrap()))
        exit(1)

    if args.open and args.violations:

        def pofilter(po):
            return not po.is_closed() or po.is_violated()
    elif args.open:

        def pofilter(po):
            return not po.is_closed()
    elif args.violations:

        def pofilter(po):
            return po.is_violated()
    else:

        def pofilter(po):
            return True

    print(RP.function_code_tostring(cfunction, pofilter=pofilter))
Ejemplo n.º 5
0
    except UF.CHError as e:
        print(str(e.wrap()))
        exit(1)

    if args.history:
        summarieslist = UF.read_project_summary_results_history(cpath)
    else:
        summarieslist = [ UF.read_project_summary_results(cpath) ]
   
    for summaries in summarieslist:
        # summaries = UF.read_project_summary_results(cpath)
        try:
            if summaries == None:
                sempath = os.path.join(cpath,'semantics')
                capp = CApplication(sempath)
                timestamp = os.stat(capp.path).st_ctime
                result = RP.project_proofobligation_stats_to_dict(capp)
                result['timestamp'] = timestamp
                result['project'] = cpath
                UF.save_project_summary_results(cpath, result)
                UF.save_project_summary_results_as_xml(cpath, result)
                summaries = UF.read_project_summary_results(cpath)
            print(RP.project_proofobligation_stats_dict_to_string(summaries))
        except IndexedTableError as e:
            print(
                '\n' + ('*' * 80) + '\nThe analysis results format has changed'
                + '\nYou may have to re-run the analysis first: '
                + '\n' + e.msg
                + '\n' + ('*' * 80))
    
            capp.reinitialize_tables()
            capp.update_spos()

        for i in range(5):
            capp.update_spos()
            am.generate_and_check_app("llrvisp", processes=args.maxprocesses)
            capp.reinitialize_tables()

    def filefilter(filename):
        return not (filename in ["io", "main_linux", "std_thread"])

    with timing("summarize"):

        contractviolations = capp.get_contract_condition_violations()
        if len(contractviolations) > 0:
            print(" --> " + str(len(contractviolations)) +
                  " contract violations in " + args.path)

        timestamp = os.stat(capp.path).st_ctime
        try:
            result = RP.project_proofobligation_stats_to_dict(
                capp, filefilter=filefilter)
            result["timestamp"] = timestamp
            result["project"] = cpath
            UF.save_project_summary_results(cpath, result)
        except IndexedTableError as e:
            print("\n" + ("*" * 80) +
                  "\nThe analysis results format has changed" +
                  "\nYou may have to re-run the analysis first: " + "\n" +
                  e.msg + "\n" + ("*" * 80))
    cwerequested = "all"
    if args.cwe is not None:
        cwerequested = args.cwe

    testcases = UF.get_flattened_juliet_testcases()

    projectstats = {}  # project -> (linecount, clinecount, cfuncount)

    ppoprojecttotals: Dict[Any, Any] = {}  # project -> dm -> dmtotal
    spoprojecttotals: Dict[Any, Any] = {}
    ppotagtotals: Dict[Any, Any] = {}  # tag -> dm -> dmtotal
    spotagtotals: Dict[Any, Any] = {}
    nosummary: List[Any] = []
    analysistimes: Dict[Any, Any] = {}

    dsmethods = RP.get_dsmethods([])

    for cwe in testcases:
        if not (cwerequested == "all" or cwerequested == cwe):
            continue
        for test in testcases[cwe]:
            p = cwe + ":" + test
            path = UF.get_juliet_testpath(cwe, test)
            results = UF.read_project_summary_results(path)
            if results is None:
                nosummary.append(p)
                continue
            pd = results
            try:
                ppod = pd["tagresults"]["ppos"]
                spod = pd["tagresults"]["spos"]
Ejemplo n.º 8
0
        am.create_app_primary_proofobligations(processes=args.maxprocesses)
        try:
            capp.collect_post_assumes()
            capp.reinitialize_tables()
            capp.update_spos()
        except UF.CHCError as e:
            print(str(e.wrap()))
            exit(1)

        for i in range(1):
            am.generate_and_check_app('vllrisp', processes=args.maxprocesses)
            capp.reinitialize_tables()
            capp.update_spos()

        for i in range(args.analysisrounds):
            capp.update_spos()
            am.generate_and_check_app('vllrisp', processes=args.maxprocesses)
            capp.reinitialize_tables()

    timestamp = os.stat(capp.path).st_ctime
    try:
        result = RP.project_proofobligation_stats_to_dict(capp)
        result['timestamp'] = timestamp
        result['project'] = cpath
        UF.save_project_summary_results(cpath, result)
        UF.save_project_summary_results_as_xml(cpath, result)
    except IndexedTableError as e:
        print('\n' + ('*' * 80) + '\nThe analysis results format has changed' +
              '\nYou may have to re-run the analysis first: ' + '\n' + e.msg +
              '\n' + ('*' * 80))
    print("Violation report for application " + args.path)
    print("  - ppo violations suspected: " + str(stats["ppoviolations"]))
    print("  - spo violations suspected: " + str(stats["spoviolations"]))
    print("  - open ppos: " + str(stats["openppos"]))
    print("  - open spos: " + str(stats["openspos"]))
    print("~" * 80)
    print("\n")

    if stats["ppoviolations"] + stats["spoviolations"] > 0:

        def pofilter(po):
            return po.is_violated()

        print("Violations suspected: ")
        for f in fns:
            if args.showcode:
                print(RP.function_code_violation_tostring(f))
            else:
                print(RP.function_pos_to_string(f, pofilter=pofilter))

    opencount = stats["openppos"] + stats["openspos"]

    if opencount > 0:
        print(("*" * 35) + " Important " + ("*" * 34))
        print("* Any of the " + str(opencount) +
              " open proof obligations could indicate a violation.")
        print(
            "* A program is proven safe only if ALL proof obligations are proven safe."
        )
        print("*" * 80)
Ejemplo n.º 10
0
    sempath = os.path.join(args.path, "semantics")

    cfapp = CApplication(sempath, args.cfile)
    cfile = cfapp.get_cfile()

    if args.showcode:
        if args.open and args.violations:

            def pofilter(po):
                return not po.is_closed() or po.is_violated()

        elif args.open:

            def pofilter(po):
                return not po.is_closed()

        elif args.violations:

            def pofilter(po):
                return po.is_violated()

        else:

            def pofilter(po):
                return True

        print(RP.file_code_tostring(cfile, pofilter=pofilter, showinvs=True))

    print(RP.file_proofobligation_stats_tostring(cfile))
def parse():
    parser = argparse.ArgumentParser()
    parser.add_argument("cfilename",
                        help="name of kendra c file (e.g., id115.c)")
    parser.add_argument(
        "--show_invariants",
        help="show invariants in addition to diagnostic",
        action="store_true",
    )
    args = parser.parse_args()
    return args


if __name__ == "__main__":

    args = parse()
    cfilename = args.cfilename
    try:
        cpath = UF.get_kendra_cpath(cfilename)
    except UF.CHError as e:
        print(str(e.wrap()))
        exit(1)

    sempath = os.path.join(cpath, "semantics")
    cfapp = CApplication(sempath, cfilename)
    cfile = cfapp.get_cfile()

    print(RP.file_code_tostring(cfile, showinvs=args.show_invariants))
    print(RP.file_proofobligation_stats_tostring(cfile))
    args = parse()

    try:
        cpath = UF.get_juliet_testpath(args.cwe, args.test)
        UF.check_analysis_results(cpath)
    except UF.CHError as e:
        print(str(e.wrap()))
        exit(1)

    sempath = os.path.join(cpath, "semantics")

    excludefiles = ["io.c", "main_linux.c", "std_thread.c"]

    summary = UF.read_project_summary_results(cpath)
    if summary is not None:
        print(RP.project_proofobligation_stats_dict_to_string(summary))
        exit(0)

    capp = CApplication(sempath, excludefiles=excludefiles)

    filterout = ["io", "main_linux", "std_thread"]
    dc = ["deadcode"]

    def filefilter(f):
        return f not in filterout

    print(
        RP.project_proofobligation_stats_tostring(capp,
                                                  extradsmethods=dc,
                                                  filefilter=filefilter))