界: Errors

錯誤和錯誤處理代表一種 API 類別。與錯誤處理相關的錯誤非常普遍,所以它們應該擁有自己的特殊領域。如同「API 濫用」,有兩種方法可以引入與錯誤相關的安全漏洞:最常見的一種方法是不當處理錯誤 (或根本沒有處理)。第二種是產生錯誤,這些錯誤不是給的資訊太多 (給可能的攻擊者),就是問題難以處理。

Code Correctness: Typographical Error

Abstract
合約使用了容易發生拼字錯誤的運算。
Explanation
在某項運算上的拼字錯誤可能會導致意外結果。例如,如果原本要使用 += 將數字加到變數,但卻寫成 =+,此時運算仍然有效。但是,它不會執行加法,而是重新初始化變數。

Example 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