From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 5E3883954C4A for ; Thu, 2 Jun 2022 09:08:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5E3883954C4A Received: by mail-ej1-x62f.google.com with SMTP id q21so8742767ejm.1 for ; Thu, 02 Jun 2022 02:08:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=0LukonNGAw9JMT0OJ5O6UWkWUC5vsoS+yT1CZCtR8/I=; b=kY7rRcyBoB5c1U7oDfJYSVdguxebHri7xNgBLlQIx5nE6VOZwhn/QL6P/KX1o6Q7zM O2NliXplZIkihnI2fUdLeRii0wy5zIOkmCT1WAlfMyAqfwUORQP21cy+2Kj5wE2hYoVK ji/jqQsHnakjsvTip/rdNoIzEyXyDumSZuoNeu/Kpk+ikKnAtEchKRPcSqe77+je5bty rvD6+RWtcrB+jN0RW0fJyr5dkNeZTAoKdcXH5SUhHJT2+Mf3dszqzajOg2W+jqqzEhTw 2K3Xd0PY+Nuwz5msaIqvY43Y7g6kU4lbAcWu1VcWHO5Fwiombn16Djt9rNSCzuHfMNPt h4ZQ== X-Gm-Message-State: AOAM533XpoohOHuHgunRxqXWqn+WbHW1huyXzrTgl9BOIzHHKJHtXX/c kkG7WijWX9/2ZTu8iZOlH5HlWIwQP6scAA== X-Google-Smtp-Source: ABdhPJwtWC1EQJKUhWMClfbgJ3C0M1ZZqvmam+g0J+hhEFMW2J0AOGNmxJNNl+Q6DPMc84PbYGCPAQ== X-Received: by 2002:a17:907:9725:b0:6fe:fce4:e08d with SMTP id jg37-20020a170907972500b006fefce4e08dmr3274064ejc.657.1654160934969; Thu, 02 Jun 2022 02:08:54 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id a25-20020a170906275900b006f3ef214e77sm1497416ejd.221.2022.06.02.02.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 02:08:54 -0700 (PDT) Date: Thu, 2 Jun 2022 09:08:53 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Joffrey Huguet Subject: [Ada] Fix preconditions of Interfaces.C.Strings Message-ID: <20220602090853.GA1010629@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="OXfL5xGRrasGEqWY" Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Jun 2022 09:08:57 -0000 --OXfL5xGRrasGEqWY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Preconditions of Update procedures were always true when Offset was 0. The changes enable to protect from Update_Error when Offset is 0. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/i-cstrin.ads (Update): Update precondition. --OXfL5xGRrasGEqWY Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/libgnat/i-cstrin.ads b/gcc/ada/libgnat/i-cstrin.ads --- a/gcc/ada/libgnat/i-cstrin.ads +++ b/gcc/ada/libgnat/i-cstrin.ads @@ -120,7 +120,10 @@ is with Pre => Item /= Null_Ptr - and then (if Check then Offset <= Strlen (Item) - Chars'Length), + and then + (if Check then + Strlen (Item) <= size_t'Last - Offset + and then Strlen (Item) + Offset <= Chars'Length), Global => (In_Out => C_Memory); procedure Update @@ -131,7 +134,10 @@ is with Pre => Item /= Null_Ptr - and then (if Check then Offset <= Strlen (Item) - Str'Length), + and then + (if Check then + Strlen (Item) <= size_t'Last - Offset + and then Strlen (Item) + Offset <= Str'Length), Global => (In_Out => C_Memory); Update_Error : exception; --OXfL5xGRrasGEqWY--