From patchwork Tue Jun 13 19:16:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Simmons-Talbott X-Patchwork-Id: 1794636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=NbGy011w; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QgdbD1MHLz20Vx for ; Wed, 14 Jun 2023 05:16:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11FEA3858C33 for ; Tue, 13 Jun 2023 19:16:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11FEA3858C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1686683814; bh=fRfpVpFbWpp/V7U1Ph2rXUu1k8Gv7qmmdMAfQ517/is=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=NbGy011wo656v5lsVu8WWtG+oscpWV4XIKH+RYDUTkUMIp99O++kqRk14sjABNqGU n6PQG3gCxOzsYPTjZLxz8BHJtDvLhoDjxjCNmu8NvWRWFlvTWim9qKEp3LTiiEJuV7 ENCh+BOoc/rfHUo2mIFjLPZ6IHjwReDig83cGoEc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E6EE23858C52 for ; Tue, 13 Jun 2023 19:16:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E6EE23858C52 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-223-biV1vbr_Nd2N1-9pPyCNyw-1; Tue, 13 Jun 2023 15:16:38 -0400 X-MC-Unique: biV1vbr_Nd2N1-9pPyCNyw-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-62def0f1f57so12230016d6.1 for ; Tue, 13 Jun 2023 12:16:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686683794; x=1689275794; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fRfpVpFbWpp/V7U1Ph2rXUu1k8Gv7qmmdMAfQ517/is=; b=Zq1MoBW8dXgFg+tbLGSkqVwKSNoK1mFD36W1/QDum8/cEATuTbMwQlb7ViqQArlqPh RiYXAHASCBuUg5DX9txRcf+XCwOoS4BTuLm3aMQ3DQYjDPlVb1ZUWZWyiq3ZP/h0mKpF Ypqw6hJkp5dPPX5gxdMzQWn8OsCP5Vd0ZjjpKwkIUD3/HTUeL5FNjYm6jgmNi+Cmx6CH u1VT4ihpoxNaPuzdoo/19URhh8mILX+qsV6+zdZjmBMZuAtZIIE4Dbdzy5zzCzAdiyld FelTFf2mGxkOUXZlXoCN05sLaridOxcp4IhKCmmLA3VBYydSRG1wgEFxLBcUVDAW5FTz f5Lg== X-Gm-Message-State: AC+VfDx3xtFGxTpKmqDmBR/c3nF+GtiW14GVp18O+3GaxUdiEpsw4m0R ES5gVzbH0N2viVmphhgD9CmzOccbaS/x+2ghBT38nIg2DFX7748Khma5Octcxu/jhVhxpgfNHDb pMt1fKsHJPxrm0j5S5BlRZD4MOGbusEsIuH9fMIrGd6bmpzE7DdcEhJdDCU8FhO1L4KqXYizk37 5futL6 X-Received: by 2002:a05:6214:21cd:b0:62d:f62b:29ee with SMTP id d13-20020a05621421cd00b0062df62b29eemr4051902qvh.12.1686683794602; Tue, 13 Jun 2023 12:16:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4XuGZmk4q3L2szwuZZ6cGuLAWjUD6A7iQQURonhqX0MlVtbBtNH9hRLJbpF9v2YG05SauLgQ== X-Received: by 2002:a05:6214:21cd:b0:62d:f62b:29ee with SMTP id d13-20020a05621421cd00b0062df62b29eemr4051880qvh.12.1686683794283; Tue, 13 Jun 2023 12:16:34 -0700 (PDT) Received: from oak.redhat.com (c-71-206-142-238.hsd1.va.comcast.net. [71.206.142.238]) by smtp.gmail.com with ESMTPSA id l12-20020ad4452c000000b00623813aa1d5sm4170651qvu.89.2023.06.13.12.16.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 12:16:33 -0700 (PDT) To: libc-alpha@sourceware.org, Samuel Thibault , Sergey Bugaev Cc: Joe Simmons-Talbott Subject: [PATCH v4] grantpt: Get rid of alloca Date: Tue, 13 Jun 2023 15:16:31 -0400 Message-Id: <20230613191631.1080455-1-josimmon@redhat.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Joe Simmons-Talbott via Libc-alpha From: Joe Simmons-Talbott Reply-To: Joe Simmons-Talbott Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Replace alloca with a scratch_buffer to avoid potential stack overflows. --- Changes since v3: * Explicitly set the retval for scratch_buffer_set_array_size failure. sysdeps/unix/grantpt.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sysdeps/unix/grantpt.c b/sysdeps/unix/grantpt.c index 38fce52576..226e7adb75 100644 --- a/sysdeps/unix/grantpt.c +++ b/sysdeps/unix/grantpt.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -147,10 +148,19 @@ grantpt (int fd) /* `sysconf' does not support _SC_GETGR_R_SIZE_MAX. Try a moderate value. */ grbuflen = 1024; - grtmpbuf = (char *) __alloca (grbuflen); + struct scratch_buffer sbuf; + scratch_buffer_init (&sbuf); + if (!scratch_buffer_set_array_size (&sbuf, 1, grbuflen)) + { + retval = -1; + goto cleanup; + } + grtmpbuf = sbuf.data; __getgrnam_r (TTY_GROUP, &grbuf, grtmpbuf, grbuflen, &p); if (p != NULL) tty_gid = p->gr_gid; + + scratch_buffer_free(&sbuf); } gid_t gid = tty_gid == -1 ? __getgid () : tty_gid;