Skip to content

Commit 7278401

Browse files
authored
Add integrity checks for HTTP-downloaded files
1 parent 4c9ba4f commit 7278401

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

build-bench-env.sh

+22-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ if [ "$EUID" -eq 0 ]; then
2727
SUDO=""
2828
fi
2929

30+
SHA256SUM_CMD="sha256sum"
31+
if test "$darwin" = "1"; then
32+
SHA256SUM_CMD="shasum -a 256"
33+
fi
34+
3035
curdir=`pwd`
3136
rebuild=0
3237
all=0
@@ -65,6 +70,10 @@ readonly version_lean=21d264a66d53b0a910178ae7d9529cb5886a39b6 # build fix for r
6570
readonly version_rocksdb=8.1.1
6671
readonly version_lua=v5.4.4
6772

73+
# HTTP-downloaded files checksums
74+
readonly sha256sum_sh6bench="506354d66b9eebef105d757e055bc55e8d4aea1e7b51faab3da35b0466c923a1"
75+
readonly sha256sum_sh8bench="12a8e75248c9dcbfee28245c12bc937a16ef56ec9cbfab88d0e348271667726f"
76+
6877
# allocators
6978
setup_dh=0
7079
setup_ff=0
@@ -343,6 +352,16 @@ function checkout { # name, git-tag, git repo, options
343352
write_version $1 $2 $3
344353
}
345354

355+
function check_checksum { # name, sha256sum
356+
if (echo "$2 $1" | $SHA256SUM_CMD --check --status); then
357+
echo "$1 has correct checksum"
358+
else
359+
echo "$1 has wrong checksum"
360+
echo "$2 was expected"
361+
$SHA256SUM_CMD $1
362+
fi
363+
}
364+
346365
function aptinstall {
347366
echo ""
348367
echo "> $SUDO apt install $1"
@@ -764,7 +783,7 @@ if test "$setup_redis" = "1"; then
764783
if test -d "redis-$version_redis"; then
765784
echo "$devdir/redis-$version_redis already exists; no need to download it"
766785
else
767-
wget --no-verbose "http://download.redis.io/releases/redis-$version_redis.tar.gz"
786+
wget --no-verbose "https://download.redis.io/releases/redis-$version_redis.tar.gz"
768787
tar xzf "redis-$version_redis.tar.gz"
769788
rm "./redis-$version_redis.tar.gz"
770789
fi
@@ -781,6 +800,7 @@ if test "$setup_bench" = "1"; then
781800
echo "do nothing: bench/shbench/sh6bench-new.c already exists"
782801
else
783802
wget --no-verbose http://www.microquill.com/smartheap/shbench/bench.zip
803+
check_checksum "bench.zip" "$sha256sum_sh6bench"
784804
unzip -o bench.zip
785805
dos2unix sh6bench.patch
786806
dos2unix sh6bench.c
@@ -790,6 +810,7 @@ if test "$setup_bench" = "1"; then
790810
echo "do nothing: bench/shbench/sh8bench-new.c already exists"
791811
else
792812
wget --no-verbose http://www.microquill.com/smartheap/SH8BENCH.zip
813+
check_checksum "SH8BENCH.zip" "$sha256sum_sh8bench"
793814
unzip -o SH8BENCH.zip
794815
dos2unix sh8bench.patch
795816
dos2unix SH8BENCH.C

0 commit comments

Comments
 (0)