1537
Architecture or Design Review
According to SOAR, the following detection techniques may be useful: Highly cost effective:
Inspection (IEEE 1028 standard) (can apply to requirements, design, source code, etc.) Formal
Methods / Correct-By-Construction
Effectiveness = High
Demonstrative Examples
Example 1:
Consider the following code segment:
Example Language: C (Bad)
char buf[10], cp_buf[10];
fgets(buf, 10, stdin);
strcpy(cp_buf, buf);
The programmer expects that when fgets() returns, buf will contain a null-terminated string of length
9 or less. But if an I/O error occurs, fgets() will not null-terminate buf. Furthermore, if the end of the
file is reached before any characters are read, fgets() returns without writing anything to buf. In both
of these situations, fgets() signals that something unusual has happened by returning NULL, but in
this code, the warning will not be noticed. The lack of a null terminator in buf can result in a buffer
overflow in the subsequent call to strcpy().
Example 2:
The following method throws three types of exceptions.
Example Language: Java (Good)
public void doExchange() throws IOException, InvocationTargetException, SQLException {
...
}
While it might seem tidier to write
Example Language: (Bad)
public void doExchange() throws Exception {
...
}
doing so hampers the caller's ability to understand and handle the exceptions that occur. Further,
if a later revision of doExchange() introduces a new type of exception that should be treated
differently than previous exceptions, there is no easy way to enforce this requirement.
Observed Examples
Reference Description
[REF-1374] Chain: JavaScript-based cryptocurrency library can fall back to the insecure
Math.random() function instead of reporting a failure (CWE-392), thus reducing
the entropy (CWE-332) and leading to generation of non-unique cryptographic
keys for Bitcoin wallets (CWE-1391)
https://www.unciphered.com/blog/randstorm-you-cant-patch-a-house-of-cards
CVE-2022-22224 Chain: an operating system does not properly process malformed Open
Shortest Path First (OSPF) Type/Length/Value Identifiers (TLV) (CWE-703),
which can cause the process to enter an infinite loop (CWE-835)
https://www.cve.org/CVERecord?id=CVE-2022-22224
MemberOf Relationships
CWE Version 4.14
CWE-704: Incorrect Type Conversion or Cast
CWE-704: Incorrect Type Conversion or Cast