The _getBeneficiaryIndex
helper function in the InheritanceManager contract returns the default value 0 when a beneficiary isn't found, without any indication of failure. This could lead to removing the wrong beneficiary if the requested address isn't in the array, particularly if there is a valid beneficiary at index 0.
The _getBeneficiaryIndex
function is implemented with a loop that returns the index when a match is found, but has no mechanism to indicate when a beneficiary isn't found:
This implementation has several issues:
It returns 0 (the default uint256 value) when a beneficiary isn't found
If there is a valid beneficiary at index 0, the caller has no way to distinguish between:
The beneficiary was found at index 0
The beneficiary wasn't found at all
Functions like removeBeneficiary
that use this helper could remove the wrong beneficiary
This vulnerability could lead to:
Removing the wrong beneficiary (the one at index 0) when attempting to remove a non-existent beneficiary
Incorrect validation of beneficiary status
Potential manipulation of the beneficiary list
The severity is medium because while it could lead to removing the wrong beneficiary, it requires specific conditions (attempting to remove a non-existent beneficiary when there is a valid one at index 0) and the impact is limited to beneficiary management rather than direct fund loss.
Manual code review
Modify the function to clearly indicate when a beneficiary isn't found:
And update the calling functions to check the return value:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.