Reformat comments to be less than 80 columns long.
This commit is contained in:
parent
f74076c2fa
commit
43ada0aae8
36
flawfinder
36
flawfinder
|
@ -535,21 +535,23 @@ p_looks_like_constant = re.compile(r'^\s*[A-Z][A-Z_$0-9]+\s*(-\s*1\s*)?$')
|
||||||
|
|
||||||
def c_strncat(hit):
|
def c_strncat(hit):
|
||||||
if len(hit.parameters) > 3:
|
if len(hit.parameters) > 3:
|
||||||
# A common mistake is to think that when calling strncat(dest,src,len), that
|
# A common mistake is to think that when calling strncat(dest,src,len),
|
||||||
# "len" means the ENTIRE length of the destination. This isn't true, it must
|
# that "len" means the ENTIRE length of the destination. This isn't true,
|
||||||
# be the length of the characters TO BE ADDED at most. Which is one reason that
|
# it must be the length of the characters TO BE ADDED at most.
|
||||||
# strlcat is better than strncat. We'll detect a common case of this error;
|
# Which is one reason that strlcat is better than strncat.
|
||||||
# if the length parameter is of the form "sizeof(dest)", we have this error.
|
# We'll detect a common case of this error; if the length parameter
|
||||||
|
# is of the form "sizeof(dest)", we have this error.
|
||||||
# Actually, sizeof(dest) is okay if the dest's first character is always \0,
|
# Actually, sizeof(dest) is okay if the dest's first character is always \0,
|
||||||
# but in that case the programmer should use strncpy, NOT strncat.
|
# but in that case the programmer should use strncpy, NOT strncat.
|
||||||
# The following heuristic will certainly miss some dangerous cases, but
|
# The following heuristic will certainly miss some dangerous cases, but
|
||||||
# it at least catches the most obvious situation.
|
# it at least catches the most obvious situation.
|
||||||
# This particular heuristic is overzealous; it detects ANY sizeof, instead of
|
# This particular heuristic is overzealous; it detects ANY sizeof, instead
|
||||||
# only the sizeof(dest) (where dest is given in hit.parameters[1]).
|
# of only the sizeof(dest) (where dest is given in hit.parameters[1]).
|
||||||
# However, there aren't many other likely candidates for sizeof; some people
|
# However, there aren't many other likely candidates for sizeof; some
|
||||||
# use it to capture just the length of the source, but this is just as dangerous,
|
# people use it to capture just the length of the source, but this is
|
||||||
# since then it absolutely does NOT take care of the destination maximum length
|
# just as dangerous, since then it absolutely does NOT take care of
|
||||||
# in general. It also detects if a constant is given as a length, if the
|
# the destination maximum length in general.
|
||||||
|
# It also detects if a constant is given as a length, if the
|
||||||
# constant follows common C naming rules.
|
# constant follows common C naming rules.
|
||||||
length_text=hit.parameters[3]
|
length_text=hit.parameters[3]
|
||||||
if p_dangerous_strncat.search(length_text) or p_looks_like_constant.search(length_text):
|
if p_dangerous_strncat.search(length_text) or p_looks_like_constant.search(length_text):
|
||||||
|
@ -651,8 +653,9 @@ p_safe_multi_byte = re.compile(r'^\s*sizeof\s*(\(\s*)?[A-Za-z_$0-9]+\s*(\)\
|
||||||
r'\[\s*0\s*\]\)\s*(-\s*1\s*)?$')
|
r'\[\s*0\s*\]\)\s*(-\s*1\s*)?$')
|
||||||
|
|
||||||
def c_multi_byte_to_wide_char(hit):
|
def c_multi_byte_to_wide_char(hit):
|
||||||
# Unfortunately, this doesn't detect bad calls when it's a #define or constant
|
# Unfortunately, this doesn't detect bad calls when it's a #define or
|
||||||
# set by a sizeof(), but trying to do so would create FAR too many false positives.
|
# constant set by a sizeof(), but trying to do so would create
|
||||||
|
# FAR too many false positives.
|
||||||
if len(hit.parameters)-1 >= 6:
|
if len(hit.parameters)-1 >= 6:
|
||||||
num_chars_to_copy=hit.parameters[6]
|
num_chars_to_copy=hit.parameters[6]
|
||||||
if p_dangerous_multi_byte.search(num_chars_to_copy):
|
if p_dangerous_multi_byte.search(num_chars_to_copy):
|
||||||
|
@ -660,9 +663,10 @@ def c_multi_byte_to_wide_char(hit):
|
||||||
hit.note = ("Risk is high, it appears that the size is given as bytes, but the " +
|
hit.note = ("Risk is high, it appears that the size is given as bytes, but the " +
|
||||||
"function requires size as characters.")
|
"function requires size as characters.")
|
||||||
elif p_safe_multi_byte.search(num_chars_to_copy):
|
elif p_safe_multi_byte.search(num_chars_to_copy):
|
||||||
# This isn't really risk-free, since it might not be the destination, or the
|
# This isn't really risk-free, since it might not be the destination,
|
||||||
# destination might be a character array (if it's a char pointer, the pattern
|
# or the destination might be a character array (if it's a char pointer,
|
||||||
# is actually quite dangerous, but programmers are unlikely to make that error).
|
# the pattern is actually quite dangerous, but programmers
|
||||||
|
# are unlikely to make that error).
|
||||||
hit.level = 1
|
hit.level = 1
|
||||||
hit.note = "Risk is very low, the length appears to be in characters not bytes."
|
hit.note = "Risk is very low, the length appears to be in characters not bytes."
|
||||||
add_warning(hit)
|
add_warning(hit)
|
||||||
|
|
Loading…
Reference in New Issue