界: Errors

错误和错误处理代表一类 API。与错误处理相关的错误非常普遍,因此它们应该拥有自己的专属章节。与“API 滥用”一样,有两种情况可以引入与错误相关的安全漏洞:最常见的一种是错误处理不当(或者根本不处理)。第二种是产生错误,这些错误要么(向潜在的攻击者)泄露过多信息,要么难以处理。

Code Correctness: Typographical Error

Abstract
合约使用了一个容易出现印刷错误的操作。
Explanation
操作中的印刷错误可能会导致意外结果。例如,如果旨在使用 += 将数字与变量相加,但写为 =+,操作仍然有效。但是,它不会执行加法,而是重新初始化变量。

示例 1 以下代码旨在将一个数字与变量 numberOne 相加。但是,使用 =+ 运算符实际上会将变量重新初始化为 1。


uint numberOne = 1;

function alwaysOne() public {
numberOne =+ 1;
}
References
[1] Enterprise Ethereum Alliance Typographic Conventions
[2] Standards Mapping - CIS Azure Kubernetes Service Benchmark 2
[3] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[4] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 3
[5] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[6] Standards Mapping - Common Weakness Enumeration CWE ID 480
[7] Standards Mapping - Smart Contract Weakness Classification SWC-129
desc.structural.solidity.swc129