mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Ensure that public callable parameters are valid for calldata.
This commit is contained in:
parent
6093982606
commit
f6d1cee06b
@ -488,6 +488,8 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
|
||||
if (auto referenceType = dynamic_cast<ReferenceType const*>(varType))
|
||||
{
|
||||
auto result = referenceType->validForLocation(referenceType->location());
|
||||
if (result && _variable.isPublicCallableParameter())
|
||||
result = referenceType->validForLocation(DataLocation::CallData);
|
||||
if (!result)
|
||||
{
|
||||
solAssert(!result.message().empty(), "Expected detailed error message");
|
||||
|
@ -559,6 +559,18 @@ bool VariableDeclaration::isExternalCallableParameter() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VariableDeclaration::isPublicCallableParameter() const
|
||||
{
|
||||
if (!isCallableOrCatchParameter())
|
||||
return false;
|
||||
|
||||
if (auto const* callable = dynamic_cast<CallableDeclaration const*>(scope()))
|
||||
if (callable->visibility() == Visibility::Public)
|
||||
return !isReturnParameter();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VariableDeclaration::isInternalCallableParameter() const
|
||||
{
|
||||
if (!isCallableOrCatchParameter())
|
||||
|
@ -914,6 +914,8 @@ public:
|
||||
/// @returns true if this variable is a parameter (not return parameter) of an external function.
|
||||
/// This excludes parameters of external function type names.
|
||||
bool isExternalCallableParameter() const;
|
||||
/// @returns true if this variable is a parameter (not return parameter) of a public function.
|
||||
bool isPublicCallableParameter() const;
|
||||
/// @returns true if this variable is a parameter or return parameter of an internal function
|
||||
/// or a function type of internal visibility.
|
||||
bool isInternalCallableParameter() const;
|
||||
|
@ -36,7 +36,7 @@ namespace solidity::util
|
||||
///
|
||||
|
||||
template <class ResultType>
|
||||
class Result
|
||||
class [[nodiscard]] Result
|
||||
{
|
||||
public:
|
||||
/// Constructs a result with _value and an empty message.
|
||||
|
@ -2,8 +2,10 @@ contract C {
|
||||
function f(bytes32[1263941234127518272][500] memory) public pure {}
|
||||
function f(uint[2**30][] memory) public pure {}
|
||||
function f(uint[2**30][2**30][] memory) public pure {}
|
||||
function f(uint[2**16][2**16][] memory) public pure {}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (26-66): Type too large for memory.
|
||||
// TypeError: (96-116): Type too large for memory.
|
||||
// TypeError: (146-173): Type too large for memory.
|
||||
// TypeError: (203-230): Type too large for calldata.
|
||||
|
Loading…
Reference in New Issue
Block a user