界: Code Quality

程式碼品質不佳,會導致無法預料的行為。從使用者的角度來看,這通常表現為可用性不佳。對於攻擊者而言,這提供了以意想不到的方式向系統施加壓力的機會。

Undefined Behavior

Abstract
未定義函數運作方式,除非將其控制參數設為某特定值。
Explanation
Linux Standard Base Specification 2.0.1 for libc 對一些內部函數的引數設定某些限制 [1]。如果函數參數不滿足這些約束條件的話,就無法成功定義此函數運作方式。


在下列 File System 函數中,必須將 1 值傳送給第一個參數 (版本編號):


__xmknod


在下列寬字元字串函數中,必須將 2 值傳送給第三個參數 (群組引數):


__wcstod_internal
__wcstof_internal
_wcstol_internal
__wcstold_internal
__wcstoul_internal


在下列 File System 函數中,必須將 3 值傳送給第一個參數 (版本編號):


__xstat
__lxstat
__fxstat
__xstat64
__lxstat64
__fxstat64

References
[1] The Linux Standard Base Specification 2.0.1, Interfaces Definitions for libc.
[2] Standards Mapping - Common Weakness Enumeration CWE ID 475
[3] Standards Mapping - Motor Industry Software Reliability Association (MISRA) C Guidelines 2012 Rule 1.3
desc.semantic.cpp.undefined_behavior