From patchwork Wed Jun 7 18:21:39 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: 1791880 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=8.43.85.97; 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=isLuEIGG; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4Qbwfq2hClz20WP for ; Thu, 8 Jun 2023 04:22:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3CE3E3857727 for ; Wed, 7 Jun 2023 18:22:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CE3E3857727 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1686162129; bh=J1yku1nXS62LkjqVR1Om/mgCi00GghmsSEqAu2xFtM0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=isLuEIGGvWWdVIkmJXU78/g/Yx1BKbbwm32rYUTzkLd+1HUFykKmsPSjXW1V2RP6O /3bT6As81/YSWrYp6UfuUF85KrVMDXHeiwCczxI9ecDx443V+UcGKCPwKwtTKAKlT2 6ckd4WsZCbadpDA21tTBJd/QpHYYXX+HeTKmm54I= 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 670643858C54 for ; Wed, 7 Jun 2023 18:21:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 670643858C54 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-3-wytJxuaWMkuFQwWKHTh_-g-1; Wed, 07 Jun 2023 14:21:51 -0400 X-MC-Unique: wytJxuaWMkuFQwWKHTh_-g-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6260e66ec46so79654836d6.3 for ; Wed, 07 Jun 2023 11:21:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686162111; x=1688754111; 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=J1yku1nXS62LkjqVR1Om/mgCi00GghmsSEqAu2xFtM0=; b=f0EtfwzcN7/oT7S3jVFLX8Ep9FSvIHnHzvOplyNzxJhEojRdAn6OaTwxM9PQ3Q7I9u mWp4moBRlOP2WcFOuQhh4RL5ApdXOKMFNJWJ81qUdW308P2P01w59hiTlYNdhuZS+aIR IokC0S9a/F9dZPMAlE4h5akdZIUcRL6d4Vl2U6RqCEBprBKYgTOXmRxheNwVErhNILZw umIiB0QLPDXBqtoIggdXTEJJFPAYx9wGUtNMocfLUZK6zWTWPCfVY83zsRdvXMa21Iqi c0Iln+2L0IiwjSyTWdWYMxrDgkWZiSnq6mqt13ybjsir7ZSjCAP7QLacr/zAjOBu8N6H 8hFg== X-Gm-Message-State: AC+VfDwHuIG7oCLg2EJpOOwZZgDWa6yDXq23mrD6aZydXOIUmWb9p89D uoNEEcuEfFjVrxkKMSZycurtrGPJkacsn0khXG8aSiqkd6ceCeadGVyry4mwMwi6xMc1nHWjYiq 40wWDoRz+1dFBJaqf0gEW X-Received: by 2002:a05:6214:248f:b0:62b:5fc9:7491 with SMTP id gi15-20020a056214248f00b0062b5fc97491mr4258762qvb.30.1686162111380; Wed, 07 Jun 2023 11:21:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ77RSr55JD/Eo2tOurrl7l3Q1RahqtDujHAJEfBklxe5aAxOkVdS373oWVI/djx6s1eIaPH7A== X-Received: by 2002:a05:6214:248f:b0:62b:5fc9:7491 with SMTP id gi15-20020a056214248f00b0062b5fc97491mr4258750qvb.30.1686162111130; Wed, 07 Jun 2023 11:21:51 -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 q18-20020a0ce212000000b0062623d8ab7esm83908qvl.111.2023.06.07.11.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 11:21:50 -0700 (PDT) To: Samuel Thibault , Sergey Bugaev , libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v2] grantpt: Get rid of alloca Date: Wed, 7 Jun 2023 14:21:39 -0400 Message-Id: <20230607182139.1995884-1-josimmon@redhat.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 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. Checked with build-many-glibcs.py on i686-gnu. --- Changes to v1: * Move scratch_buffer_free call into same scope as the scratch_buffer and use the address of the scratch_buffer for scratch_buffer_free. 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..77c8d814cc 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;