[openwrt/openwrt] scripts/getver.sh: prevent asking for negative rev-parse

LEDE Commits lede-commits at lists.infradead.org
Sun Nov 12 07:20:10 PST 2023


ansuel pushed a commit to openwrt/openwrt.git, branch openwrt-22.03:
https://git.openwrt.org/86124a1b3a2f0b955adfbebb3f2bd2c288837aac

commit 86124a1b3a2f0b955adfbebb3f2bd2c288837aac
Author: Christian Marangi <ansuelsmth at gmail.com>
AuthorDate: Sun Nov 12 16:15:07 2023 +0100

    scripts/getver.sh: prevent asking for negative rev-parse
    
    With the case of asking an invalid version that is too big, getver.sh
    might return an invalid output in the form of HEAD~-2260475641.
    
    This is caused by BASE_REV - GET_REV using a negative number.
    
    Prevent this by checking if BASE_REV - GET_REV actually return 0 or a
    positive number and set REV variable accordingly. With the following
    change, invalid revision number will result in unknown printed instead
    of the invalid HEAD~-NUMBERS output.
    
    Signed-off-by: Christian Marangi <ansuelsmth at gmail.com>
    (cherry picked from commit 9e49e0a6c4535d345084cc62c594be5cad23b911)
---
 scripts/getver.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/getver.sh b/scripts/getver.sh
index 49260a2260..61906040b1 100755
--- a/scripts/getver.sh
+++ b/scripts/getver.sh
@@ -21,7 +21,7 @@ try_git() {
 	r*)
 		GET_REV="$(echo $GET_REV | tr -d 'r')"
 		BASE_REV="$(git rev-list ${REBOOT}..HEAD 2>/dev/null | wc -l | awk '{print $1}')"
-		REV="$(git rev-parse HEAD~$((BASE_REV - GET_REV)))"
+		[ $((BASE_REV - GET_REV)) -ge 0 ] && REV="$(git rev-parse HEAD~$((BASE_REV - GET_REV)))"
 		;;
 	*)
 		BRANCH="$(git rev-parse --abbrev-ref HEAD)"




More information about the lede-commits mailing list