diff --git a/flawfinder b/flawfinder index be573e5..eb0af45 100755 --- a/flawfinder +++ b/flawfinder @@ -49,6 +49,7 @@ # than Python 2.7. from __future__ import division +from __future__ import print_function import functools import sys import re @@ -244,7 +245,7 @@ def load_patch_info(input_patch_file): try: hPatch = open(input_patch_file, 'r') except BaseException: - print "Error: failed to open", h(input_patch_file) + print("Error: failed to open", h(input_patch_file)) sys.exit(1) patched_filename = "" # Name of new file patched by current hunk. @@ -258,7 +259,7 @@ def load_patch_info(input_patch_file): elif is_gnu_diff(sLine): fn_get_filename = gnu_diff_get_filename else: - print "Error: Unrecognized patch format" + print("Error: Unrecognized patch format") sys.exit(1) while True: # Loop-and-half construct. Read a line, end loop when no more @@ -328,18 +329,18 @@ def print_multi_line(text): prefix = " " starting_position = len(prefix) + 1 # - print prefix, + print(prefix, end='') position = starting_position # for w in text.split(): if len(w) + position >= width: - print - print prefix, + print() + print(prefix, end='') position = starting_position - print w, + print(' ', end='') + print(w, end='') position = position + len(w) + 1 - # This matches references to CWE identifiers, so we can HTMLize them. # We don't refer to CWEs with one digit, so we'll only match on 2+ digits. link_cwe_pattern = re.compile(r'(CWE-([1-9][0-9]+))([,()])') @@ -431,49 +432,49 @@ class Hit(object): self.show_csv() return if output_format: - print "
" - print h(self.context_text) + print("") # The "hitlist" is the list of all hits (warnings) found so far. @@ -499,7 +500,7 @@ def add_warning(hit): def internal_warn(message): - print h(message) + print(h(message)) # C Language Specific @@ -1442,9 +1443,9 @@ def process_c_file(f, patch_infos): # This file isn't in the patch list, so don't bother analyzing it. if not quiet: if output_format: - print "Skipping unpatched file ", h(f), "") + print(h(self.context_text)) if output_format: - print "" + print("
" + print("
") if list_rules: display_ruleset(c_ruleset) sys.exit(0) @@ -1653,20 +1654,20 @@ def display_header(): print( '') - print "" - print "
" - print '' - print "" + print("
")
else:
- print
+ print()
if count > 0:
- print "Hits =", count
+ print("Hits =", count)
else:
- print "No hits found."
+ print("No hits found.")
if output_format:
- print "
"
+ print("
")
# Compute the amount of time spent, and lines analyzed/second.
# By computing time here, we also include the time for
# producing the list of hits, which is reasonable.
time_analyzing = time.time() - starttime
if required_regex:
- print "Hits limited to regular expression " + required_regex
- print "Lines analyzed = %d" % sumlines,
+ print("Hits limited to regular expression " + required_regex)
+ print("Lines analyzed = %d" % sumlines, end='')
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))
+ print(" in approximately %.2f seconds (%.0f lines/second)" % (
+ time_analyzing, (sumlines / time_analyzing)))
else:
- print
+ print()
if output_format:
- print "
"
- print "Physical Source Lines of Code (SLOC) = %d" % sloc
+ print("
")
+ print("Physical Source Lines of Code (SLOC) = %d" % sloc)
if output_format:
- print "
"
+ print("
")
# Output hits@each level.
- print "Hits@level =",
+ print("Hits@level =", end='')
for i in range(0, 6):
- print "[%d] %3d" % (i, count_per_level[i]),
+ print(" [%d] %3d" % (i, count_per_level[i]), end='')
if output_format:
- print "
"
+ print("
")
else:
- print
+ print()
# Compute hits at "level x or higher"
- print "Hits@level+ =",
+ print("Hits@level+ =", end='')
for i in range(0, 6):
for j in range(i, 6):
count_per_level_and_up[
i] = count_per_level_and_up[i] + count_per_level[j]
# Display hits at "level x or higher"
for i in range(0, 6):
- print "[%d+] %3d" % (i, count_per_level_and_up[i]),
+ print(" [%d+] %3d" % (i, count_per_level_and_up[i]), end='')
if output_format:
- print "
"
+ print("
")
else:
- print
+ print()
if sloc > 0:
- print "Hits/KSLOC@level+ =",
+ print("Hits/KSLOC@level+ =", end='')
for i in range(0, 6):
- print "[%d+] %3g" % (
- i, count_per_level_and_up[i] * 1000.0 / sloc),
+ print(" [%d+] %3g" % (
+ i, count_per_level_and_up[i] * 1000.0 / sloc), end='')
if output_format:
- print "
"
+ print("
")
else:
- print
+ print()
#
if num_links_skipped:
- print "Symlinks skipped =", num_links_skipped, "(--allowlink overrides but see doc for security issue)"
+ print("Symlinks skipped =", num_links_skipped, "(--allowlink overrides but see doc for security issue)")
if output_format:
- print "
"
+ print("
")
if num_dotdirs_skipped:
- print "Dot directories skipped =", num_dotdirs_skipped, "(--followdotdir overrides)"
+ print("Dot directories skipped =", num_dotdirs_skipped, "(--followdotdir overrides)")
if output_format:
- print "
"
+ print("
")
if num_ignored_hits > 0:
- print "Suppressed hits =", num_ignored_hits, "(use --neverignore to show them)"
+ print("Suppressed hits =", num_ignored_hits, "(use --neverignore to show them)")
if output_format:
- print "
"
- print "Minimum risk level = %d" % minimum_level
+ print("
")
+ print("Minimum risk level = %d" % minimum_level)
if output_format:
- print "
"
+ print("
")
if count > 0:
- print "Not every hit is necessarily a security vulnerability."
+ print("Not every hit is necessarily a security vulnerability.")
if output_format:
- print "
"
- print "There may be other security vulnerabilities; review your code!"
+ print("
")
+ print("There may be other security vulnerabilities; review your code!")
if output_format:
- print "
"
- print "See 'Secure Programming for Linux and Unix HOWTO'"
- print "(http://www.dwheeler.com/secure-programs) for more information."
+ print("
")
+ print("See 'Secure Programming for Linux and Unix HOWTO'")
+ print("(http://www.dwheeler.com/secure-programs) for more information.")
else:
- print "See 'Secure Programming for Linux and Unix HOWTO'"
- print "(http://www.dwheeler.com/secure-programs) for more information."
+ print("See 'Secure Programming for Linux and Unix HOWTO'")
+ print("(http://www.dwheeler.com/secure-programs) for more information.")
if output_format:
- print ""
- print ""
+ print("")
+ print("")
def save_if_desired():
# We'll save entire hitlist, even if only differences displayed.
if savehitlist:
- print "Saving hitlist to", savehitlist
+ print("Saving hitlist to", savehitlist)
f = open(savehitlist, "w")
pickle.dump(hitlist, f)
f.close()
@@ -2162,4 +2163,4 @@ if __name__ == '__main__':
try:
flawfind()
except KeyboardInterrupt:
- print "*** Flawfinder interrupted"
+ print("*** Flawfinder interrupted")