From ff85124328b724e193a0f20f9c239d1ef4944203 Mon Sep 17 00:00:00 2001 From: Fabien Chouteau Date: Fri, 17 Jul 2020 19:13:42 +0200 Subject: [PATCH] Alire.Origins: check length of git and hg commit id (#476) And raise a meaningful exception instead of Constraint_Error. --- src/alire/alire-origins.adb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/alire/alire-origins.adb b/src/alire/alire-origins.adb index a0f7eeed..707e3fda 100644 --- a/src/alire/alire-origins.adb +++ b/src/alire/alire-origins.adb @@ -172,8 +172,24 @@ package body Alire.Origins is Utils.Starts_With (From, Prefixes (Kind).all) then case Kind is - when Git => This := New_Git (URL, Commit); - when Hg => This := New_Hg (URL, Commit); + when Git => + if Commit'Length /= Git_Commit'Length then + Raise_Checked_Error + ("invalid git commit id, " & + "40 digits hexadecimal expected"); + end if; + + This := New_Git (URL, Commit); + + when Hg => + if Commit'Length /= Hg_Commit'Length then + Raise_Checked_Error + ("invalid hg revision number, " & + "40 digits hexadecimal expected"); + end if; + + This := New_Hg (URL, Commit); + when SVN => This := New_SVN (URL, Commit); when External => This := New_External (Descr); -- 2.39.5