Assert used as the only validation for untrusted input
ID |
c.miscellaneous.suspicious_assert |
Severity |
low |
Resource |
Miscellaneous |
Language |
C / C++ |
Description
Most codebases define assertion macros which compile to a no-op on non-debug builds. If assertions are the only line of defense against untrusted input, the software may be exposed to attacks that leverage the lack of proper input checks.
Rationale
Most codebases define assertion macros which compile to a no-op on non-debug builds. If assertions are the only line of defense against untrusted input, the software may be exposed to attacks that leverage the lack of proper input checks.
The following code illustrates a vulnerable pattern detected by this rule:
void bt_mesh_beacon_priv_random_get(uint8_t *random, size_t size)
{
// VULNERABLE: Assert used as the only validation for untrusted input
__ASSERT(size <= sizeof(priv_random.val), "Invalid random value size %u", size);
memcpy(random, priv_random.val, size);
}
Remediation
Follow secure coding practices and review the references below for detailed remediation guidance.