The _getBeneficiaryIndex function, used as a helper for removeBeneficiary, has a critical flaw: if the specified _beneficiary address is not found in the beneficiaries array, it silently returns 0 instead of indicating an error. This causes the first beneficiary (at index 0) to be incorrectly targeted for removal, undermining the owner’s intent and disrupting the inheritance structure.
The vulnerable code is in the _getBeneficiaryIndex function:
solidity
Silent Default Return:
The function initializes _index to 0 implicitly (Solidity’s default for uint256).
If the loop completes without finding _beneficiary, it returns 0 instead of signaling that the address wasn’t found.
This falsely indicates that the beneficiary at index 0 should be acted upon.
Dependency in removeBeneficiary:
The removeBeneficiary function relies on _getBeneficiaryIndex:
solidity
If _beneficiary isn’t in the array, index 0 is deleted, removing the first beneficiary instead of reverting or skipping the operation.
No Validation:
There’s no check to confirm whether the returned index corresponds to the actual _beneficiary, allowing unintended removals.
Incorrect Beneficiary Removal: The first beneficiary (index 0) loses their inheritance rights if an invalid address is passed, violating the owner’s intent.
Inheritance Disruption: Subsequent operations (e.g., withdrawInheritedFunds) treat address(0) as a valid beneficiary, potentially sending funds to the zero address or skewing distribution calculations.
Owner Confusion: The owner may unknowingly remove the wrong beneficiary, with no indication of the error, reducing trust in the contract’s reliability.
Potential Exploitation: While not directly exploitable by external parties due to onlyOwner, it could lead to accidental fund loss if the owner mistakenly inputs an incorrect address.
Manual review
Modify _getBeneficiaryIndex to explicitly validate the beneficiary’s presence and revert if not found. Here’s a corrected version:
solidity
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.