48 lines
1.1 KiB
Solidity
48 lines
1.1 KiB
Solidity
/*
|
|
* @source: https://github.com/SmartContractSecurity/SWC-registry/blob/master/test_cases/dos_gas_limit/dos_number.sol
|
|
* @author: -
|
|
* @vulnerable_at_lines: 18,19,20,21,22
|
|
*/
|
|
|
|
pragma solidity ^0.4.25;
|
|
|
|
contract DosNumber {
|
|
|
|
uint numElements = 0;
|
|
uint[] array;
|
|
|
|
function insertNnumbers(uint value,uint numbers) public {
|
|
|
|
// Gas DOS if number > 382 more or less, it depends on actual gas limit
|
|
// <yes> <report> DENIAL_OF_SERVICE
|
|
for(uint i=0;i<numbers;i++) {
|
|
if(numElements == array.length) {
|
|
array.length += 1;
|
|
}
|
|
array[numElements++] = value;
|
|
}
|
|
}
|
|
|
|
function clear() public {
|
|
require(numElements>1500);
|
|
numElements = 0;
|
|
}
|
|
|
|
// Gas DOS clear
|
|
function clearDOS() public {
|
|
|
|
// number depends on actual gas limit
|
|
require(numElements>1500);
|
|
array = new uint[](0);
|
|
numElements = 0;
|
|
}
|
|
|
|
function getLengthArray() public view returns(uint) {
|
|
return numElements;
|
|
}
|
|
|
|
function getRealLengthArray() public view returns(uint) {
|
|
return array.length;
|
|
}
|
|
}
|