|
|
Home » U++ Library support » U++ Core » Patch to fix few possible issues
Patch to fix few possible issues [message #56106] |
Mon, 25 January 2021 15:34  |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |

|
|
hi! I've been working on possible security issues with U++ project and came across PVS-Studio as a nice static analysis tool. Since only U++ Core was used, it was processed by PVS-Studio and a number of potential security-related issues was found (collected in xlsx file). So here is a patch for U++ Core to fix possible issues found (looks like very few of those important).
[Updated on: Mon, 25 January 2021 15:35] Report message to a moderator
|
|
|
|
|
Re: Patch to fix few possible issues [message #56123 is a reply to message #56121] |
Fri, 29 January 2021 11:30   |
 |
Klugier
Messages: 1099 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello Koldo,
You could try to use flawfinder tool for scanning security issues in the C/C++ code. Sometimes, it produces false positives (Here is the ticket I raised to this tool), but the output are generally acceptable.
Here is the output for Function4U:
Toggle Spoiler
Flawfinder version 2.0.11, (C) 2001-2019 David A. Wheeler.
Number of rules (primarily dangerous function names) in C/C++ ruleset: 223
Examining Functions4U/GatherTpp.h
Examining Functions4U/Bsdiff/bspatch.cpp
Examining Functions4U/Bsdiff/bsadditional.cpp
Examining Functions4U/Bsdiff/bsdiff.cpp
Examining Functions4U/Functions4U_Gui.cpp
Examining Functions4U/GatherTpp.cpp
Examining Functions4U/bsdiff.h
Examining Functions4U/LocalProcess2.cpp
Examining Functions4U/StaticPlugin.cpp
Examining Functions4U/SvgColors.h
Examining Functions4U/Html/htmld.h
Examining Functions4U/Html/htmld.cpp
Examining Functions4U/LocalProcess2.h
Examining Functions4U/SvgColors.cpp
Examining Functions4U/Functions4U_Gui.h
Examining Functions4U/StaticPlugin.h
Examining Functions4U/QtfEquation.cpp
Examining Functions4U/Functions4U.cpp
Examining Functions4U/Functions4U.h
FINAL RESULTS:
Functions4U/Functions4U.cpp:380: [5] (race) chmod:
This accepts filename arguments; if an attacker can move those files, a
race condition results. (CWE-362). Use fchmod( ) instead.
Functions4U/Functions4U.cpp:129: [4] (shell) system:
This causes a new program to execute and is difficult to use safely
(CWE-78). try using a library call that implements the same functionality
if available.
Functions4U/Functions4U.cpp:131: [4] (shell) system:
This causes a new program to execute and is difficult to use safely
(CWE-78). try using a library call that implements the same functionality
if available.
Functions4U/Functions4U.cpp:135: [4] (shell) system:
This causes a new program to execute and is difficult to use safely
(CWE-78). try using a library call that implements the same functionality
if available.
Functions4U/Functions4U.cpp:137: [4] (shell) system:
This causes a new program to execute and is difficult to use safely
(CWE-78). try using a library call that implements the same functionality
if available.
Functions4U/LocalProcess2.cpp:293: [4] (shell) execl:
This causes a new program to execute and is difficult to use safely
(CWE-78). try using a library call that implements the same functionality
if available.
Functions4U/LocalProcess2.cpp:331: [4] (shell) execv:
This causes a new program to execute and is difficult to use safely
(CWE-78). try using a library call that implements the same functionality
if available.
Functions4U/Functions4U.cpp:2577: [3] (misc) LoadLibraryEx:
Ensure that the full path to the library is specified, or current directory
may be used (CWE-829, CWE-20). Use registry entry or GetWindowsDirectory to
find library path, if you aren't already.
Functions4U/LocalProcess2.cpp:231: [3] (buffer) getenv:
Environment variables are untrustable input if they can be set by an
attacker. They can have any content and length, and the same variable can
be set more than once (CWE-807, CWE-20). Check environment variables
carefully before using them.
Functions4U/Bsdiff/bsdiff.cpp:227: [2] (misc) open:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Bsdiff/bsdiff.cpp:254: [2] (misc) open:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Bsdiff/bsdiff.cpp:278: [2] (misc) fopen:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Bsdiff/bsdiff.cpp:294: [2] (buffer) memcpy:
Does not check for buffer overflows when copying to destination (CWE-120).
Make sure destination can always hold the source data.
Functions4U/Bsdiff/bspatch.cpp:85: [2] (misc) fopen:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Bsdiff/bspatch.cpp:128: [2] (misc) fopen:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Bsdiff/bspatch.cpp:140: [2] (misc) fopen:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Bsdiff/bspatch.cpp:152: [2] (misc) fopen:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Bsdiff/bspatch.cpp:165: [2] (misc) open:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Bsdiff/bspatch.cpp:237: [2] (misc) open:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Functions4U.cpp:254: [2] (buffer) char:
Statically-sized arrays can be improperly restricted, leading to potential
overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use
functions that limit length, or ensure that the size is larger than the
maximum possible length.
Functions4U/Functions4U.cpp:557: [2] (misc) open:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Functions4U.cpp:566: [2] (buffer) char:
Statically-sized arrays can be improperly restricted, leading to potential
overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use
functions that limit length, or ensure that the size is larger than the
maximum possible length.
Functions4U/Functions4U.cpp:578: [2] (misc) open:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Functions4U.cpp:638: [2] (buffer) char:
Statically-sized arrays can be improperly restricted, leading to potential
overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use
functions that limit length, or ensure that the size is larger than the
maximum possible length.
Functions4U/Functions4U.cpp:721: [2] (buffer) char:
Statically-sized arrays can be improperly restricted, leading to potential
overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use
functions that limit length, or ensure that the size is larger than the
maximum possible length.
Functions4U/Functions4U.cpp:727: [2] (buffer) char:
Statically-sized arrays can be improperly restricted, leading to potential
overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use
functions that limit length, or ensure that the size is larger than the
maximum possible length.
Functions4U/Functions4U.cpp:1719: [2] (misc) open:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Functions4U.cpp:1727: [2] (misc) open:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Functions4U.cpp:1769: [2] (misc) fopen:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Functions4U.cpp:1981: [2] (misc) fopen:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Functions4U.cpp:2024: [2] (misc) fopen:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
Functions4U/Functions4U.cpp:2067: [2] (integer) atoi:
Unless checked, the resulting number can exceed the expected range
(CWE-190). If source untrusted, check both minimum and maximum, even if the
input had no minus sign (large numbers can roll over into negative number;
consider saving to an unsigned value if that is intended).
Functions4U/Functions4U.cpp:2067: [2] (integer) atoi:
Unless checked, the resulting number can exceed the expected range
(CWE-190). If source untrusted, check both minimum and maximum, even if the
input had no minus sign (large numbers can roll over into negative number;
consider saving to an unsigned value if that is intended).
Functions4U/LocalProcess2.cpp:183: [2] (buffer) memcpy:
Does not check for buffer overflows when copying to destination (CWE-120).
Make sure destination can always hold the source data.
Functions4U/LocalProcess2.cpp:188: [2] (buffer) memcpy:
Does not check for buffer overflows when copying to destination (CWE-120).
Make sure destination can always hold the source data.
Functions4U/LocalProcess2.cpp:236: [2] (buffer) memcpy:
Does not check for buffer overflows when copying to destination (CWE-120).
Make sure destination can always hold the source data.
Functions4U/LocalProcess2.cpp:251: [2] (race) vfork:
On some old systems, vfork() permits race conditions, and it's very
difficult to use correctly (CWE-362). Use fork() instead.
Functions4U/LocalProcess2.cpp:533: [2] (buffer) char:
Statically-sized arrays can be improperly restricted, leading to potential
overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use
functions that limit length, or ensure that the size is larger than the
maximum possible length.
Functions4U/LocalProcess2.cpp:566: [2] (buffer) char:
Statically-sized arrays can be improperly restricted, leading to potential
overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use
functions that limit length, or ensure that the size is larger than the
maximum possible length.
Functions4U/Bsdiff/bsdiff.cpp:238: [1] (buffer) read:
Check buffer boundaries if used in a loop including recursive loops
(CWE-120, CWE-20).
Functions4U/Bsdiff/bsdiff.cpp:265: [1] (buffer) read:
Check buffer boundaries if used in a loop including recursive loops
(CWE-120, CWE-20).
Functions4U/Bsdiff/bspatch.cpp:174: [1] (buffer) read:
Check buffer boundaries if used in a loop including recursive loops
(CWE-120, CWE-20).
Functions4U/Functions4U.cpp:567: [1] (buffer) read:
Check buffer boundaries if used in a loop including recursive loops
(CWE-120, CWE-20).
Functions4U/Functions4U.cpp:593: [1] (buffer) read:
Check buffer boundaries if used in a loop including recursive loops
(CWE-120, CWE-20).
Functions4U/Functions4U.cpp:1534: [1] (buffer) strlen:
Does not handle strings that are not \0-terminated; if given one it may
perform an over-read (it could cause a crash if unprotected) (CWE-126).
Functions4U/Functions4U.cpp:1536: [1] (buffer) strlen:
Does not handle strings that are not \0-terminated; if given one it may
perform an over-read (it could cause a crash if unprotected) (CWE-126).
Functions4U/Functions4U.cpp:1738: [1] (buffer) read:
Check buffer boundaries if used in a loop including recursive loops
(CWE-120, CWE-20).
Functions4U/Functions4U.cpp:1739: [1] (buffer) read:
Check buffer boundaries if used in a loop including recursive loops
(CWE-120, CWE-20).
Functions4U/Functions4U.cpp:1781: [1] (buffer) fgetc:
Check buffer boundaries if used in a loop including recursive loops
(CWE-120, CWE-20).
Functions4U/Functions4U.cpp:1984: [1] (buffer) fgetc:
Check buffer boundaries if used in a loop including recursive loops
(CWE-120, CWE-20).
Functions4U/Functions4U.cpp:2031: [1] (buffer) fgetc:
Check buffer boundaries if used in a loop including recursive loops
(CWE-120, CWE-20).
Functions4U/Functions4U.cpp:2342: [1] (buffer) equal:
Function does not check the second iterator for over-read conditions
(CWE-126). This function is often discouraged by most C++ coding standards
in favor of its safer alternatives provided since C++14. Consider using a
form of this function that checks the second iterator before potentially
overflowing it.
Functions4U/Functions4U.cpp:2698: [1] (buffer) strlen:
Does not handle strings that are not \0-terminated; if given one it may
perform an over-read (it could cause a crash if unprotected) (CWE-126).
Functions4U/Functions4U.cpp:2699: [1] (buffer) strlen:
Does not handle strings that are not \0-terminated; if given one it may
perform an over-read (it could cause a crash if unprotected) (CWE-126).
Functions4U/Functions4U.cpp:2727: [1] (buffer) strlen:
Does not handle strings that are not \0-terminated; if given one it may
perform an over-read (it could cause a crash if unprotected) (CWE-126).
Functions4U/Functions4U.cpp:2728: [1] (buffer) strlen:
Does not handle strings that are not \0-terminated; if given one it may
perform an over-read (it could cause a crash if unprotected) (CWE-126).
Functions4U/Functions4U.cpp:2764: [1] (buffer) strlen:
Does not handle strings that are not \0-terminated; if given one it may
perform an over-read (it could cause a crash if unprotected) (CWE-126).
Functions4U/Functions4U.cpp:2765: [1] (buffer) strlen:
Does not handle strings that are not \0-terminated; if given one it may
perform an over-read (it could cause a crash if unprotected) (CWE-126).
Functions4U/Functions4U.h:371: [1] (buffer) strlen:
Does not handle strings that are not \0-terminated; if given one it may
perform an over-read (it could cause a crash if unprotected) (CWE-126).
Functions4U/LocalProcess2.cpp:176: [1] (buffer) strlen:
Does not handle strings that are not \0-terminated; if given one it may
perform an over-read (it could cause a crash if unprotected) (CWE-126).
Functions4U/LocalProcess2.cpp:182: [1] (buffer) strlen:
Does not handle strings that are not \0-terminated; if given one it may
perform an over-read (it could cause a crash if unprotected) (CWE-126).
Functions4U/LocalProcess2.cpp:193: [1] (buffer) strlen:
Does not handle strings that are not \0-terminated; if given one it may
perform an over-read (it could cause a crash if unprotected) (CWE-126).
Functions4U/LocalProcess2.cpp:325: [1] (buffer) strlen:
Does not handle strings that are not \0-terminated; if given one it may
perform an over-read (it could cause a crash if unprotected) (CWE-126).
Functions4U/LocalProcess2.cpp:567: [1] (buffer) read:
Check buffer boundaries if used in a loop including recursive loops
(CWE-120, CWE-20).
Functions4U/QtfEquation.cpp:266: [1] (buffer) equal:
Function does not check the second iterator for over-read conditions
(CWE-126). This function is often discouraged by most C++ coding standards
in favor of its safer alternatives provided since C++14. Consider using a
form of this function that checks the second iterator before potentially
overflowing it.
Functions4U/bsdiff.h:19: [1] (buffer) read:
Check buffer boundaries if used in a loop including recursive loops
(CWE-120, CWE-20).
ANALYSIS SUMMARY:
Hits = 66
Lines analyzed = 8458 in approximately 0.10 seconds (88475 lines/second)
Physical Source Lines of Code (SLOC) = 7076
Hits@level = [0] 3 [1] 27 [2] 30 [3] 2 [4] 6 [5] 1
Hits@level+ = [0+] 69 [1+] 66 [2+] 39 [3+] 9 [4+] 7 [5+] 1
Hits/KSLOC@level+ = [0+] 9.75127 [1+] 9.3273 [2+] 5.51159 [3+] 1.27191 [4+] 0.989259 [5+] 0.141323
Minimum risk level = 1
Not every hit is necessarily a security vulnerability.
There may be other security vulnerabilities; review your code!
See 'Secure Programming HOWTO'
(https://dwheeler.com/secure-programs) for more information.
On my distro (Manjaro) you can download flawfinder as a package.
Klugier
U++ - one framework to rule them all.
|
|
|
|
|
Re: Patch to fix few possible issues [message #56171 is a reply to message #56134] |
Wed, 03 February 2021 09:22  |
 |
koldo
Messages: 3435 Registered: August 2008
|
Senior Veteran |
|
|
After reviewing both:
- flawfinder gives generic advices, e.g., if it finds a system() call, it advices to replace it with the specific OS function. Not bad, but generic
- cppcheck seems to really check the sources in detail, giving very specific advices
So cppcheck, although it sometimes fails, seems more useful.
Best regards
Iñaki
|
|
|
Goto Forum:
Current Time: Sun May 11 20:17:34 CEST 2025
Total time taken to generate the page: 0.00479 seconds
|
|
|