From 8c580997c905e566e0f7b063942f45a416919aa7 Mon Sep 17 00:00:00 2001 From: Reza Date: Fri, 17 Feb 2023 16:33:41 +0330 Subject: [PATCH] check github api status code to avoid undefined behavior in case of errors --- install-release.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/install-release.sh b/install-release.sh index 0313525..ac11f0b 100644 --- a/install-release.sh +++ b/install-release.sh @@ -243,11 +243,17 @@ get_version() { fi # Get V2Ray release version number TMP_FILE="$(mktemp)" - if ! curl -x "${PROXY}" -sS -H "Accept: application/vnd.github.v3+json" -o "$TMP_FILE" 'https://api.github.com/repos/v2fly/v2ray-core/releases/latest'; then + if ! curl -x "${PROXY}" -sS -i -H "Accept: application/vnd.github.v3+json" -o "$TMP_FILE" 'https://api.github.com/repos/v2fly/v2ray-core/releases/latest'; then "rm" "$TMP_FILE" echo 'error: Failed to get release list, please check your network.' exit 1 fi + HTTP_STATUS_CODE="$(awk 'NR==1 {print $2}' "$TMP_FILE")" + if [ "$HTTP_STATUS_CODE" != "200" ]; then + "rm" "$TMP_FILE" + echo "error: Failed to get release list, GitHub API response code: $HTTP_STATUS_CODE" + exit 1 + fi RELEASE_LATEST="$(sed 'y/,/\n/' "$TMP_FILE" | grep 'tag_name' | awk -F '"' '{print $4}')" "rm" "$TMP_FILE" RELEASE_VERSION="v${RELEASE_LATEST#v}"