From patchwork Thu Dec 2 16:28:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 48394 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED6263858036 for ; Thu, 2 Dec 2021 16:29:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED6263858036 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638462551; bh=05RfQsALw4yBPjdd4yJaxT1iBUqznZ7pRIy7N0DRjHM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=B03lRR4c3dNWw7FO6MXqtGR2AT+JXSquRuJ9luPhncwDXnVAqus15lyjSXci5L051 u78XSPmKlALbmFiHriocfVyUgYQLf6ofk1o/O9OojOhq6xp+4UxELO8d9IizoVpjIe ES33XLt7W2HXAu0Vo8js1EMpH5tNEYd4h2aZ57Zw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 7F5D7385782C for ; Thu, 2 Dec 2021 16:28:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7F5D7385782C Received: by mail-wm1-x335.google.com with SMTP id p3-20020a05600c1d8300b003334fab53afso2748933wms.3 for ; Thu, 02 Dec 2021 08:28:34 -0800 (PST) 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=05RfQsALw4yBPjdd4yJaxT1iBUqznZ7pRIy7N0DRjHM=; b=F87Vn1G+QvK3fZdb6EW+meisZ+n1CidctPeSUpv9WyH9d/GMu2QvVMOryqUbT314hv J1J/vGrd9OotTLuh2JAUvVGzKVE6315W5WkE4v0gCqA6dU83NFH3a18J1uYCVJ6SCOd4 APIo0gDinGBXo2lalDPO0K7tVLdish0iGx5OF0/7tpZ1vd1DU59//kIiS3cFBSzWwDNk nEHRlM1YO47T5j8IV0aS/AvkIrN2nTiPIc1TOzI7esoDHFEhpy1StaYpTzxGGJwF+Cb6 Pu26G5us+P+fA2xmsDYIslrZ4niaFZWbCkHwMlg9jJMSzO+ZFWJOANf4BwSKtDcuX3u/ sTww== X-Gm-Message-State: AOAM532jkBXBpUszeVNqz3jCF4oRQnY1h4NIHnJRAg0d2kHy3uV+6Kpo 2L0dWTO0HxuMl/k7vl3Ur3HMu+YQEXx3WA== X-Google-Smtp-Source: ABdhPJzkXQaWDlcxLRyNw1MSW+1Vjn0M78HbJrQpIl3Mn+xYULujJ5yK1L0C5WmMq6NO5EgLssozFQ== X-Received: by 2002:a05:600c:a08:: with SMTP id z8mr7678622wmp.165.1638462513324; Thu, 02 Dec 2021 08:28:33 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id g18sm3396920wmq.4.2021.12.02.08.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 08:28:32 -0800 (PST) Date: Thu, 2 Dec 2021 16:28:31 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix possible memory corruption for hostnames longer than 1024 bytes Message-ID: <20211202162831.GA2156148@adacore.com> MIME-Version: 1.0 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 autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Pascal Obry Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When a hostname has more than 1024 characters, Constraint_Error is raised if the runtime is compiled with checks on, otherwise a memory corruption occurs. Use the constant NI_MAXHOST to ensure that the appropriate buffer size is allocated for the hostnames. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/g-socket.ads (Max_Name_Length): Initialize with NI_MAXHOST. diff --git a/gcc/ada/libgnat/g-socket.ads b/gcc/ada/libgnat/g-socket.ads --- a/gcc/ada/libgnat/g-socket.ads +++ b/gcc/ada/libgnat/g-socket.ads @@ -1558,8 +1558,10 @@ private No_Sock_Addr : constant Sock_Addr_Type := (Family_Inet, No_Inet_Addr, 0); - Max_Name_Length : constant := 64; - -- The constant MAXHOSTNAMELEN is usually set to 64 + Max_Name_Length : constant := SOSC.NI_MAXHOST; + -- Most systems don't provide constants that specify the maximum size + -- of either a FQDN or a service name. In order to aid applications in + -- allocating buffers, the constant NI_MAXHOST is defined in . subtype Name_Index is Natural range 1 .. Max_Name_Length;