Skip to content

Commit

Permalink
detect multiline entries for check-reentrancy script (#2287)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec authored May 11, 2023
1 parent 1a710fc commit 6f61568
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions scripts/check-forbid-evm-reentrancy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@
while IFS= read -r path
do
echo "$path"
while IFS= read -r line
do
matches=$(echo "$line" | awk '(/^pallet-evm = / || /^pallet-ethereum = /) && !/reentrancy/');
if [ ! -z "$matches" ]; then
echo "Check fails: $line"
echo "Please add 'forbid-evm-reentrancy' feature to 'pallet-evm' and 'pallet-ethereum'."
exit 1
fi
done < "$path"
done < <(find . -name "Cargo.toml" -not -path "*/target/*" -not -path "*/build/*")

# Detect single or multiline declarations of pallet-evm and pallet-ethereum to
# contain the "forbid-evm-reentrancy" feature.
matches=$(awk 'flag{
if (buf ~ /}/ && buf !~ /forbid-evm-reentrancy/) {
printf "(line %d) %s", line, buf; flag=0; buf="" # single line declaration
} else {
buf = buf $0 ORS;
if (flag && /}/ && buf !~ /forbid-evm-reentrancy/) { # multiline declaration
printf "(line %d) %s", line, buf; flag=0; buf=""
}
}
}
/pallet-(ethereum|evm) = /{buf = $0 ORS; flag=1;line=NR}' "${path}")

if [[ -n "$matches" ]]; then
echo "Check failed. Please add 'forbid-evm-reentrancy' feature to 'pallet-evm' and 'pallet-ethereum'."
echo "${matches}"
exit 1
fi
done < <(find . -name "Cargo.toml" -not -path "*/target/*" -not -path "*/build/*")

0 comments on commit 6f61568

Please sign in to comment.