界: Code Quality

代码质量不佳会导致不可预测的行为。对于用户来说,通常表现为可用性差。对于攻击者来说,提供了以意外方式对系统施加压力的机会。

Undefined Behavior

Abstract
除非该函数的控制参数设置为一个特定值,否则无法定义的行为。
Explanation
The 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