界: Errors

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

Denial of Service: External Call

Abstract
函數在迴圈陳述式內呼叫外部合約,這可能會導致 Denial of Service。
Explanation
對外部合約的呼叫可能會失敗,如果未正確處理失敗,可能會導致呼叫端合約內部發生 Denial of Service 情況。這可能會使合約無法進一步使用。

當外部呼叫在迴圈陳述式內執行時 (尤其是在處理付款時),這一點尤其重要,此時最好讓使用者提領資金,而不是向其推送資金。

範例 1:以下程式碼使用 for 迴圈陳述式,藉由使用 send 外部呼叫來進行所有相關位址的退款。


function refundAll() public {
for(uint x; x < refundAddresses.length; x++) {
require(refundAddresses[x].send(refunds[refundAddresses[x]]));
}
}
References
[1] Standards Mapping - CIS Azure Kubernetes Service Benchmark 2
[2] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[3] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 3
[4] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[5] Standards Mapping - Common Weakness Enumeration CWE ID 703
[6] Standards Mapping - Smart Contract Weakness Classification SWC-113
desc.structural.solidity.swc113