Don't use addition to wrap low-level error codes by high-level error codes #2462
Labels
component-crypto
Crypto primitives and low-level interfaces
component-tls
component-x509
enhancement
good-first-issue
Good for newcomers
historical-reviewed
Reviewed & agreed to keep legacy PR/issue
Issue: If a high-level function (e.g. X.509) calls a low-level function (e.g. ASN.1) and the latter fails, the high-level function usually wraps the low-level error code by something like
Functionally, that's OK because low-level and high-level error codes don't have bits in common, but it has the following deficiencies:
ret = high_level(); if( ret != 0 ) return( ret );
, then the compiler cannot squash the tworeturn
statements into one because it cannot argue thatHIGH_LEVEL + ret
doesn't lead to0
being returned.+
could in theory overflow and lead to unintended behaviour.Task: Switch to a different idiom, e.g. returning
HIGH_LEVEL | ret
instead ofHIGH_LEVEL + ret
, throughout the library.The text was updated successfully, but these errors were encountered: