diff --git a/Makefile.amiga b/Makefile.amiga new file mode 100644 index 0000000..3795452 --- /dev/null +++ b/Makefile.amiga @@ -0,0 +1,20 @@ +# +# Project: flawfinder +# Created by George "walkero" Sokianos +# 2022-07-25 +# + +release: clean + mkdir -p release/flawfinder + cp -r release_files/* release/flawfinder/ + cp flawfinder.py release/flawfinder/flawfinder + protect release/flawfinder/flawfinder srwed + cp -r simplejson release/flawfinder + cp ChangeLog release/flawfinder/ + cp README.md release/flawfinder/ + cp COPYING release/flawfinder/ + lha -aeqr3 a flawfinder.lha release/ + +clean: + rm -f simplejson/#?.pyc + diff --git a/flawfinder.py b/flawfinder.py old mode 100755 new mode 100644 index 1e7eb04..63de5a5 --- a/flawfinder.py +++ b/flawfinder.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!python """flawfinder: Find potential security flaws ("hits") in source code. Usage: @@ -40,7 +40,7 @@ # That *finally* makes it possible to semi-gracefully transition. from __future__ import division -from __future__ import print_function +# from __future__ import print_function import functools import sys import re @@ -53,7 +53,7 @@ import operator # To support filename expansion on Windows import time import csv # To support generating CSV format import hashlib -import json +import simplejson as json version = "2.0.19" @@ -488,16 +488,16 @@ def print_multi_line(text): prefix = " " starting_position = len(prefix) + 1 # - print(prefix, end='') + print(prefix), position = starting_position # for w in text.split(): if len(w) + position >= width: - print() - print(prefix, end='') + print '\n', + print(prefix), position = starting_position - print(' ', end='') - print(w, end='') + # print(' '), + print(w), position += len(w) + 1 @@ -608,44 +608,44 @@ class Hit(object): if sarif_output: return if output_format: - print("
") @@ -676,7 +676,8 @@ def add_warning(hit): def internal_warn(message): - print(h(message), file=sys.stderr) + # print(h(message), file=sys.stderr) + print h(message) # C Language Specific @@ -1756,9 +1757,9 @@ def process_c_file(f, patch_infos): if not quiet: if output_format: - print("Examining", h(f), "
") + print 'Examining %s
' % (h(f)) else: - print("Examining", f) + print 'Examining %s' % (h(f)) sys.stdout.flush() # Python3 is often configured to use only UTF-8, and presumes @@ -1767,10 +1768,10 @@ def process_c_file(f, patch_infos): # in such cases - with some hints on how to solve it. try: text = "".join(my_input.readlines()) - except UnicodeDecodeError as err: + except UnicodeDecodeError, err: print('Error: encoding error in', h(f)) print(err) - print() + print '\n', print('Python3 requires input character data to be perfectly encoded;') print('it also requires perfectly correct system encoding settings.') print('Unfortunately, your data and/or system settings are not.') @@ -1948,8 +1949,7 @@ def display_ruleset(ruleset): def initialize_ruleset(): expand_ruleset(c_ruleset) if showheading: - print("Number of rules (primarily dangerous function names) in C/C++ ruleset:", len( - c_ruleset)) + print 'Number of rules (primarily dangerous function names) in C/C++ ruleset: %d' % len(c_ruleset) if output_format: print("") if list_rules: @@ -2313,7 +2313,7 @@ def process_options(): diffhitlist_filename = value display_header() if showheading: - print("Showing hits not in", value) + print("Showing hits not in %s" % value) elif opt == "--version": print(version) sys.exit(0) @@ -2338,7 +2338,7 @@ def process_options(): # In Python 2 the convention is "getopt.GetoptError", but we # use "getopt.error" here so it's compatible with both # Python 1.5 and Python 2. - except getopt.error as text: + except getopt.error, text: print("*** getopt error:", text) usage() sys.exit(16) @@ -2384,13 +2384,13 @@ def show_final_results(): for i in possible_levels: # Initialize count_per_level_and_up count_per_level_and_up[i] = 0 if show_immediately or not quiet: # Separate the final results. - print() + print '\n', if showheading: if output_format: print("
Final Results
") else: print("FINAL RESULTS:") - print() + print '\n', hitlist.sort(key=hitlist_sort_key) # Display results. The HTML format now uses #
")
else:
- print()
+ print '\n',
if count > 0:
- print("Hits =", count)
+ print 'Hits = %d' % count
else:
print("No hits found.")
if output_format:
@@ -2436,27 +2436,27 @@ def show_final_results():
time_analyzing = time.time() - starttime
if required_regex:
print("Hits limited to regular expression " + required_regex)
- print("Lines analyzed = %d" % sumlines, end='')
+ print("Lines analyzed = %d" % sumlines),
if time_analyzing > 0 and not omit_time: # Avoid divide-by-zero.
print(" in approximately %.2f seconds (%.0f lines/second)" % (
time_analyzing, (sumlines / time_analyzing)))
else:
- print()
+ print '\n',
if output_format:
print("
")
print("Physical Source Lines of Code (SLOC) = %d" % sloc)
if output_format:
print("
")
# Output hits@each level.
- print("Hits@level =", end='')
+ print("Hits@level ="),
for i in possible_levels:
- print(" [%d] %3d" % (i, count_per_level[i]), end='')
+ print(" [%d] %3d" % (i, count_per_level[i])),
if output_format:
print("
")
else:
- print()
+ print '\n',
# Compute hits at "level x or higher"
- print("Hits@level+ =", end='')
+ print("Hits@level+ ="),
for i in possible_levels:
for j in possible_levels:
if j >= i:
@@ -2464,20 +2464,20 @@ def show_final_results():
i] = count_per_level_and_up[i] + count_per_level[j]
# Display hits at "level x or higher"
for i in possible_levels:
- print(" [%d+] %3d" % (i, count_per_level_and_up[i]), end='')
+ print(" [%d+] %3d" % (i, count_per_level_and_up[i])),
if output_format:
print("
")
else:
- print()
+ print '\n',
if sloc > 0:
- print("Hits/KSLOC@level+ =", end='')
+ print("Hits/KSLOC@level+ ="),
for i in possible_levels:
print(" [%d+] %3g" % (
- i, count_per_level_and_up[i] * 1000.0 / sloc), end='')
+ i, count_per_level_and_up[i] * 1000.0 / sloc)),
if output_format:
print("
")
else:
- print()
+ print '\n',
#
if num_links_skipped:
print("Symlinks skipped =", num_links_skipped, "(--allowlink overrides but see doc for security issue)")
@@ -2488,14 +2488,14 @@ def show_final_results():
if output_format:
print("
")
if num_ignored_hits > 0:
- print("Suppressed hits =", num_ignored_hits, "(use --neverignore to show them)")
+ print("Suppressed hits = %d (use --neverignore to show them)" % num_ignored_hits)
if output_format:
print("
")
print("Minimum risk level = %d" % minimum_level)
if output_format:
print("
")
else:
- print()
+ print '\n',
if count > 0:
print("Not every hit is necessarily a security vulnerability.")
print("You can inhibit a report by adding a comment in this form:")
@@ -2505,7 +2505,7 @@ def show_final_results():
if output_format:
print("
")
else:
- print()
+ print '\n',
print("There may be other security vulnerabilities; review your code!")
if output_format:
print("
")
@@ -2550,3 +2550,4 @@ def main():
if __name__ == '__main__':
main()
+